mlflow API Reference
Full documentation for mlflow (3.15.0)
mlflow.ActiveModel
Python Library Documentation: class ActiveModel in module mlflow.tracking.fluent class ActiveModel(mlflow.entities.logged_model.LoggedModel) | ActiveModel(logged_model: mlflow.entities.logged_model.LoggedModel, set_by_user: bool) | | Wrapper around :py:class:`mlflow.entities.LoggedModel` to enable using Python ``with`` syntax. | | Method resolution order: | ActiveModel | mlflow.entities.logged_model.LoggedModel | mlflow.entities._mlflow_object._MlflowObject | builtins.object | | Methods defined here: | | __enter__(self) | | __exit__(self, exc_type, exc_val, exc_tb) | | __init__(self, logged_model: mlflow.entities.logged_model.LoggedModel, set_by_user: bool) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from mlflow.entities.logged_model.LoggedModel: | | __repr__(self) -> str | Return repr(self). | | to_dictionary(self) -> dict[str, typing.Any] | | to_proto(self) | | ---------------------------------------------------------------------- | Class methods inherited from mlflow.entities.logged_model.LoggedModel: | | from_proto(proto) | | ---------------------------------------------------------------------- | Readonly properties inherited from mlflow.entities.logged_model.LoggedModel: | | creation_timestamp | Integer. Model creation timestamp (milliseconds since the Unix epoch). | | model_uri | URI of the model. | | params | Model parameters. | | source_run_id | String. MLflow run ID that generated this model. | | status_message | String. Descriptive message for error status conditions. | | tags | Dictionary of tag key (string) -> tag value for this Model. | | ---------------------------------------------------------------------- | Data descriptors inherited from mlflow.entities.logged_model.LoggedModel: | | artifact_location | String. Location of the model artifacts. | | experiment_id | String. Experiment ID associated with this Model. | | last_updated_timestamp | Integer. Timestamp of last update for this Model (milliseconds since the Unix | epoch). | | metrics | List of metrics associated with this Model. | | model_id | String. Unique ID for this Model. | | model_type | String. Type of the model. | | name | String. Name for this Model. | | status | String. Current status of this Model. | | ---------------------------------------------------------------------- | Methods inherited from mlflow.entities._mlflow_object._MlflowObject: | | __iter__(self) | | ---------------------------------------------------------------------- | Class methods inherited from mlflow.entities._mlflow_object._MlflowObject: | | from_dictionary(the_dict) | | ---------------------------------------------------------------------- | Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
mlflow.ActiveRun
Python Library Documentation: class ActiveRun in module mlflow.tracking.fluent class ActiveRun(mlflow.entities.run.Run) | ActiveRun(run) | | Wrapper around :py:class:`mlflow.entities.Run` to enable using Python ``with`` syntax. | | Method resolution order: | ActiveRun | mlflow.entities.run.Run | mlflow.entities._mlflow_object._MlflowObject | builtins.object | | Methods defined here: | | __enter__(self) | | __exit__(self, exc_type, exc_val, exc_tb) | | __init__(self, run) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from mlflow.entities.run.Run: | | to_dictionary(self) -> dict[typing.Any, typing.Any] | | to_proto(self) | | ---------------------------------------------------------------------- | Class methods inherited from mlflow.entities.run.Run: | | from_proto(proto) | | ---------------------------------------------------------------------- | Readonly properties inherited from mlflow.entities.run.Run: | | data | The run data, including metrics, parameters, and tags. | | :rtype: :py:class:`mlflow.entities.RunData` | | info | The run metadata, such as the run id, start time, and status. | | :rtype: :py:class:`mlflow.entities.RunInfo` | | inputs | The run inputs, including dataset inputs. | | :rtype: :py:class:`mlflow.entities.RunInputs` | | outputs | The run outputs, including model outputs. | | :rtype: :py:class:`mlflow.entities.RunOutputs` | | ---------------------------------------------------------------------- | Methods inherited from mlflow.entities._mlflow_object._MlflowObject: | | __iter__(self) | | __repr__(self) | Return repr(self). | | ---------------------------------------------------------------------- | Class methods inherited from mlflow.entities._mlflow_object._MlflowObject: | | from_dictionary(the_dict) | | ---------------------------------------------------------------------- | Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
mlflow.IS_TRACING_SDK_ONLY
Python Library Documentation: bool object class bool(int) | bool(x) -> bool | | Returns True when the argument x is true, False otherwise. | The builtins True and False are the only two instances of the class bool. | The class bool is a subclass of the class int, and cannot be subclassed. | | Method resolution order: | bool | int | object | | Methods defined here: | | __and__(self, value, /) | Return self&value. | | __invert__(self, /) | ~self | | __or__(self, value, /) | Return self|value. | | __rand__(self, value, /) | Return value&self. | | __repr__(self, /) | Return repr(self). | | __ror__(self, value, /) | Return value|self. | | __rxor__(self, value, /) | Return value^self. | | __xor__(self, value, /) | Return self^value. | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from int: | | __abs__(self, /) | abs(self) | | __add__(self, value, /) | Return self+value. | | __bool__(self, /) | True if self else False | | __ceil__(...) | Ceiling of an Integral returns itself. | | __divmod__(self, value, /) | Return divmod(self, value). | | __eq__(self, value, /) | Return self==value. | | __float__(self, /) | float(self) | | __floor__(...) | Flooring an Integral returns itself. | | __floordiv__(self, value, /) | Return self//value. | | __format__(self, format_spec, /) | Convert to a string according to format_spec. | | __ge__(self, value, /) | Return self>=value. | | __getattribute__(self, name, /) | Return getattr(self, name). | | __getnewargs__(self, /) | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __index__(self, /) | Return self converted to an integer, if self is suitable for use as an index into a list. | | __int__(self, /) | int(self) | | __le__(self, value, /) | Return self<=value. | | __lshift__(self, value, /) | Return self<<value. | | __lt__(self, value, /) | Return self<value. | | __mod__(self, value, /) | Return self%value. | | __mul__(self, value, /) | Return self*value. | | __ne__(self, value, /) | Return self!=value. | | __neg__(self, /) | -self | | __pos__(self, /) | +self | | __pow__(self, value, mod=None, /) | Return pow(self, value, mod). | | __radd__(self, value, /) | Return value+self. | | __rdivmod__(self, value, /) | Return divmod(value, self). | | __rfloordiv__(self, value, /) | Return value//self. | | __rlshift__(self, value, /) | Return value<<self. | | __rmod__(self, value, /) | Return value%self. | | __rmul__(self, value, /) | Return value*self. | | __round__(...) | Rounding an Integral returns itself. | | Rounding with an ndigits argument also returns an integer. | | __rpow__(self, value, mod=None, /) | Return pow(value, self, mod). | | __rrshift__(self, value, /) | Return value>>self. | | __rshift__(self, value, /) | Return self>>value. | | __rsub__(self, value, /) | Return value-self. | | __rtruediv__(self, value, /) | Return value/self. | | __sizeof__(self, /) | Returns size in memory, in bytes. | | __sub__(self, value, /) | Return self-value. | | __truediv__(self, value, /) | Return self/value. | | __trunc__(...) | Truncating an Integral returns itself. | | as_integer_ratio(self, /) | Return a pair of integers, whose ratio is equal to the original int. | | The ratio is in lowest terms and has a positive denominator. | | >>> (10).as_integer_ratio() | (10, 1) | >>> (-10).as_integer_ratio() | (-10, 1) | >>> (0).as_integer_ratio() | (0, 1) | | bit_count(self, /) | Number of ones in the binary representation of the absolute value of self. | | Also known as the population count. | | >>> bin(13) | '0b1101' | >>> (13).bit_count() | 3 | | bit_length(self, /) | Number of bits necessary to represent self in binary. | | >>> bin(37) | '0b100101' | >>> (37).bit_length() | 6 | | conjugate(...) | Returns self, the complex conjugate of any int. | | is_integer(self, /) | Returns True. Exists for duck type compatibility with float.is_integer. | | to_bytes(self, /, length=1, byteorder='big', *, signed=False) | Return an array of bytes representing an integer. | | length | Length of bytes object to use. An OverflowError is raised if the | integer is not representable with the given number of bytes. Default | is length 1. | byteorder | The byte order used to represent the integer. If byteorder is 'big', | the most significant byte is at the beginning of the byte array. If | byteorder is 'little', the most significant byte is at the end of the | byte array. To request the native byte order of the host system, use | `sys.byteorder' as the byte order value. Default is to use 'big'. | signed | Determines whether two's complement is used to represent the integer. | If signed is False and a negative integer is given, an OverflowError | is raised. | | ---------------------------------------------------------------------- | Class methods inherited from int: | | from_bytes(bytes, byteorder='big', *, signed=False) | Return the integer represented by the given array of bytes. | | bytes | Holds the array of bytes to convert. The argument must either | support the buffer protocol or be an iterable object producing bytes. | Bytes and bytearray are examples of built-in objects that support the | buffer protocol. | byteorder | The byte order used to represent the integer. If byteorder is 'big', | the most significant byte is at the beginning of the byte array. If | byteorder is 'little', the most significant byte is at the end of the | byte array. To request the native byte order of the host system, use | `sys.byteorder' as the byte order value. Default is to use 'big'. | signed | Indicates whether two's complement is used to represent the integer. | | ---------------------------------------------------------------------- | Data descriptors inherited from int: | | denominator | the denominator of a rational number in lowest terms | | imag | the imaginary part of a complex number | | numerator | the numerator of a rational number in lowest terms | | real | the real part of a complex number
mlflow.Image
Python Library Documentation: class Image in module mlflow.tracking.multimedia
class Image(builtins.object)
| Image(image: Union[ForwardRef('numpy.ndarray'), ForwardRef('PIL.Image.Image'), str, list[Any]])
|
| `mlflow.Image` is an image media object that provides a lightweight option
| for handling images in MLflow.
| The image can be a numpy array, a PIL image, or a file path to an image. The image is
| stored as a PIL image and can be logged to MLflow using `mlflow.log_image` or
| `mlflow.log_table`.
|
| Args:
| image: Image can be a numpy array, a PIL image, or a file path to an image.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| import numpy as np
| from PIL import Image
|
| # Create an image as a numpy array
| image = np.zeros((100, 100, 3), dtype=np.uint8)
| image[:, :50] = [255, 128, 0]
| # Create an Image object
| image_obj = mlflow.Image(image)
| # Convert the Image object to a list of pixel values
| pixel_values = image_obj.to_list()
|
| Methods defined here:
|
| __init__(self, image: Union[ForwardRef('numpy.ndarray'), ForwardRef('PIL.Image.Image'), str, list[Any]])
| Initialize self. See help(type(self)) for accurate signature.
|
| resize(self, size: tuple[int, int])
| Resize the image to the specified size.
|
| Args:
| size: Size to resize the image to.
|
| Returns:
| A copy of the resized image object.
|
| save(self, path: str)
| Save the image to a file.
|
| Args:
| path: File path to save the image.
|
| to_array(self)
| Convert the image to a numpy array.
|
| Returns:
| Numpy array of pixel values.
|
| to_list(self)
| Convert the image to a list of pixel values.
|
| Returns:
| List of pixel values.
|
| to_pil(self)
| Convert the image to a PIL image.
|
| Returns:
| PIL image.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
mlflow.LazyLoader
Python Library Documentation: class LazyLoader in module mlflow.utils.lazy_load
class LazyLoader(builtins.module)
| LazyLoader(local_name, parent_module_globals, name)
|
| Class for module lazy loading.
|
| This class helps lazily load modules at package level, which avoids pulling in large
| dependencies like `tensorflow` or `torch`. This class is mirrored from wandb's LazyLoader:
| https://github.com/wandb/wandb/blob/79b2d4b73e3a9e4488e503c3131ff74d151df689/wandb/sdk/lib/lazyloader.py#L9
|
| Method resolution order:
| LazyLoader
| builtins.module
| builtins.object
|
| Methods defined here:
|
| __dir__(self)
| __dir__() -> list
| specialized dir() implementation
|
| __getattr__(self, item)
|
| __init__(self, local_name, parent_module_globals, name)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.module:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.module:
|
| __new__(*args, **kwargs) class method of builtins.module
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.module:
|
| __dict__
mlflow.MLFLOW_CONFIGURE_LOGGING
Python Library Documentation: _BooleanEnvironmentVariable in module mlflow.environment_variables object class _BooleanEnvironmentVariable(_EnvironmentVariable) | _BooleanEnvironmentVariable(name, default) | | Represents a boolean environment variable. | | Method resolution order: | _BooleanEnvironmentVariable | _EnvironmentVariable | builtins.object | | Methods defined here: | | __init__(self, name, default) | Initialize self. See help(type(self)) for accurate signature. | | get(self) | Reads the value of the environment variable if it exists and converts it to the desired | type. Otherwise, returns the default value. | | ---------------------------------------------------------------------- | Methods inherited from _EnvironmentVariable: | | __format__(self, format_spec: str) -> str | Default object formatter. | | Return str(self) if format_spec is empty. Raise TypeError otherwise. | | __repr__(self) | Return repr(self). | | __str__(self) | Return str(self). | | get_raw(self) | | is_set(self) | | set(self, value) | | unset(self) | | ---------------------------------------------------------------------- | Readonly properties inherited from _EnvironmentVariable: | | defined | | ---------------------------------------------------------------------- | Data descriptors inherited from _EnvironmentVariable: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
mlflow.MlflowClient
Python Library Documentation: class MlflowClient in module mlflow.tracking.client
class MlflowClient(builtins.object)
| MlflowClient(tracking_uri: str | None = None, registry_uri: str | None = None, workspace_store_uri: str | None = None)
|
| Client of an MLflow Tracking Server that creates and manages experiments and runs, and of an
| MLflow Registry Server that creates and manages registered models and model versions. It also
| exposes workspace CRUD via the configured workspace provider. It's a thin wrapper around:
|
| - TrackingServiceClient for tracking operations
| - WorkspaceProviderClient for workspace operations
| - ModelRegistryClient for registry operations
|
| This layered structure provides a unified API while preserving independent implementations.
|
| Methods defined here:
|
| __init__(self, tracking_uri: str | None = None, registry_uri: str | None = None, workspace_store_uri: str | None = None)
| Args:
| tracking_uri: Address of local or remote tracking server. If not provided, defaults
| to the service set by ``mlflow.tracking.set_tracking_uri``. See
| `Where Runs Get Recorded <../tracking.html#where-runs-get-recorded>`_
| for more info.
| registry_uri: Address of local or remote model registry server. If not provided,
| defaults to the service set by ``mlflow.tracking.set_registry_uri``. If
| no such service was set, defaults to the tracking uri of the client.
| workspace_store_uri: Address of the workspace provider backend. Defaults to the tracking
| URI when unspecified, but can be pointed at a dedicated workspace store.
|
| add_dataset_to_experiments(self, dataset_id: str, experiment_ids: list[str]) -> mlflow.entities.evaluation_dataset.EvaluationDataset
| Add a dataset to additional experiments.
|
| This allows reusing datasets across multiple experiments for evaluation purposes.
|
| Args:
| dataset_id: The ID of the dataset to update.
| experiment_ids: List of experiment IDs to associate with the dataset.
|
| Returns:
| The updated EvaluationDataset with new experiment associations.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Add dataset to new experiments
| dataset = client.add_dataset_to_experiments(
| dataset_id="d-abc123", experiment_ids=["1", "2", "3"]
| )
| print(f"Dataset now associated with {len(dataset.experiment_ids)} experiments")
|
| copy_model_version(self, src_model_uri, dst_name) -> mlflow.entities.model_registry.model_version.ModelVersion
| Copy a model version from one registered model to another as a new model version.
| If the destination model does not exist, it will be created.
|
| This method can also be used to migrate model versions from the Databricks workspace
| registry to Unity Catalog. During the migration, signature validation can be bypassed
| by setting the `MLFLOW_SKIP_SIGNATURE_CHECK_FOR_UC_REGISTRY_MIGRATION`environment
| variable to `True`.
|
| Args:
| src_model_uri: The model URI of the model version to copy. This must be a model
| registry URI with a `"models:/"` scheme (e.g., `"models:/iris_model@champion"`).
| dst_name: The name of the registered model to copy the model version to. If a
| registered model with this name does not exist, it will be created.
|
| Returns:
| Single :py:class:`mlflow.entities.model_registry.ModelVersion` object representing
| the copied model version.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_version_info(mv):
| print(f"Name: {mv.name}")
| print(f"Version: {mv.version}")
| print(f"Source: {mv.source}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
|
| # Log a model
| with mlflow.start_run() as run:
| params = {"n_estimators": 3, "random_state": 42}
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Create source model version
| client = MlflowClient()
| src_name = "RandomForestRegression-staging"
| client.create_registered_model(src_name)
| src_uri = f"runs:/{run.info.run_id}/sklearn-model"
| mv_src = client.create_model_version(src_name, src_uri, run.info.run_id)
| print_model_version_info(mv_src)
| print("--")
|
| # Copy the source model version into a new registered model
| dst_name = "RandomForestRegression-production"
| src_model_uri = f"models:/{mv_src.name}/{mv_src.version}"
| mv_copy = client.copy_model_version(src_model_uri, dst_name)
| print(f"Name: {mv_copy.name}, Version: {mv_copy.version}, Source: {mv_copy.source}")
|
| .. code-block:: python
| :caption: Migration example from Databricks Workspace Model Registry to Unity Catalog
|
| from mlflow import MlflowClient
| import os
|
| os.environ["MLFLOW_SKIP_SIGNATURE_CHECK_FOR_UC_REGISTRY_MIGRATION"] = "true"
| client = MlflowClient(registry_uri="databricks")
|
| src_model_uri = f"models:/my_workspace_model/1"
| uc_model_dst_name = "mycatalog.myschema.my_uc_model"
| uc_migrated_copy = client.copy_model_version(src_model_uri, uc_model_dst_name)
| print_model_version_info(uc_migrated_copy)
|
| .. code-block:: text
| :caption: Output
|
| Name: RandomForestRegression-staging
| Version: 1
| Source: runs:/53e08bb38f0c487fa36c5872515ed998/sklearn-model
| --
| Name: RandomForestRegression-production
| Version: 1
| Source: models:/RandomForestRegression-staging/1
|
| create_dataset(self, name: str, experiment_id: str | list[str] | None = None, tags: dict[str, typing.Any] | None = None) -> mlflow.entities.evaluation_dataset.EvaluationDataset
| Create a new dataset.
|
| Args:
| name: The name of the dataset.
| experiment_id: Optional experiment ID (str) or list of experiment IDs to
| associate with the dataset.
| tags: Optional dictionary of tags to apply to the dataset.
|
| Returns:
| The created EvaluationDataset object.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Create a dataset associated with experiments
| dataset = client.create_dataset(
| name="qa_evaluation_v1",
| experiment_id=["0", "1"],
| tags={"environment": "production", "version": "1.0"},
| )
|
| create_experiment(self, name: str, artifact_location: str | None = None, tags: dict[str, typing.Any] | None = None) -> str
| Create an experiment.
|
| Args:
| name: The experiment name, which must be a unique string.
| artifact_location: The location to store run artifacts. If not provided, the server
| picks anappropriate default.
| tags: A dictionary of key-value pairs that are converted into
| :py:class:`mlflow.entities.ExperimentTag` objects, set as
| experiment tags upon experiment creation.
|
| Returns:
| String as an integer ID of the created experiment.
|
| .. code-block:: python
| :caption: Example
|
| from pathlib import Path
| from mlflow import MlflowClient
|
| # Create an experiment with a name that is unique and case sensitive.
| client = MlflowClient()
| experiment_id = client.create_experiment(
| "Social NLP Experiments",
| artifact_location=Path.cwd().joinpath("mlruns").as_uri(),
| tags={"version": "v1", "priority": "P1"},
| )
| client.set_experiment_tag(experiment_id, "nlp.framework", "Spark NLP")
|
| # Fetch experiment metadata information
| experiment = client.get_experiment(experiment_id)
| print(f"Name: {experiment.name}")
| print(f"Experiment_id: {experiment.experiment_id}")
| print(f"Artifact Location: {experiment.artifact_location}")
| print(f"Tags: {experiment.tags}")
| print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
|
| .. code-block:: text
| :caption: Output
|
| Name: Social NLP Experiments
| Experiment_id: 1
| Artifact Location: file:///.../mlruns
| Tags: {'version': 'v1', 'priority': 'P1', 'nlp.framework': 'Spark NLP'}
| Lifecycle_stage: active
|
| create_logged_model(self, experiment_id: str, name: str | None = None, source_run_id: str | None = None, tags: dict[str, str] | None = None, params: dict[str, str] | None = None, model_type: str | None = None) -> mlflow.entities.logged_model.LoggedModel
| Create a new logged model.
|
| Args:
| experiment_id: ID of the experiment to which the model belongs.
| name: Name of the model. If not specified, a random name will be generated.
| source_run_id: ID of the run that produced the model.
| tags: Tags to set on the model.
| params: Parameters to set on the model.
| model_type: The type of the model. This is a user-defined string that can be used to
| search and compare related models. For example, setting
| ``model_type="agent"`` enables you to easily search for this model and
| compare it to other models of type ``"agent"`` in the future.
|
| Returns:
| The created model.
|
| create_mcp_access_endpoint(self, server_name: str, url: str, transport_type: mlflow.entities.mcp_server.MCPRemoteTransportType = <MCPRemoteTransportType.STREAMABLE_HTTP: 'streamable-http'>, server_version: str | None = None, server_alias: str | None = None) -> mlflow.entities.mcp_access_endpoint.MCPAccessEndpoint
|
| create_mcp_server(self, name: str, description: str | None = None, icons: list[mlflow.store.tracking.mcp_server_registry.abstract_mixin.MCPIcon] | None = None) -> mlflow.entities.mcp_server.MCPServer
|
| create_mcp_server_version(self, server_json: dict[str, typing.Any], source: str | None = None, status: mlflow.entities.mcp_server.MCPStatus | None = None, tools: list[mlflow.entities.mcp_server.MCPTool] | None = <object object at 0x0000025F348EA210>, connect_options: dict[str, mlflow.entities.mcp_server_version.ConnectOptionSettings] | None = None) -> mlflow.entities.mcp_server_version.MCPServerVersion
|
| create_model_version(self, name: str, source: str, run_id: str | None = None, tags: dict[str, typing.Any] | None = None, run_link: str | None = None, description: str | None = None, await_creation_for: int = 300, model_id: str | None = None) -> mlflow.entities.model_registry.model_version.ModelVersion
| Create a new model version from given source.
|
| Args:
| name: Name for the containing registered model.
| source: URI indicating the location of the model artifacts. The artifact URI can be
| run relative (e.g. ``runs:/<run_id>/<model_artifact_path>``), a model
| registry URI (e.g. ``models:/<model_name>/<version>``), or other URIs
| supported by the model registry backend (e.g. `"s3://my_bucket/my/model"`).
| run_id: Run ID from MLflow tracking server that generated the model.
| tags: A dictionary of key-value pairs that are converted into
| :py:class:`mlflow.entities.model_registry.ModelVersionTag` objects.
| run_link: Link to the run from an MLflow tracking server that generated this model.
| description: Description of the version.
| await_creation_for: Number of seconds to wait for the model version to finish being
| created and is in ``READY`` status. By default, the function
| waits for five minutes. Specify 0 or None to skip waiting.
| model_id: The ID of the model (from an Experiment) that is being promoted to a
| registered model version, if applicable.
|
| Returns:
| Single :py:class:`mlflow.entities.model_registry.ModelVersion` object created by
| backend.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow.store.artifact.runs_artifact_repo import RunsArtifactRepository
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a new version of the rfr model under the registered model name
| desc = "A new version of the model"
| runs_uri = f"runs:/{run.info.run_id}/sklearn-model"
| model_src = RunsArtifactRepository.get_underlying_uri(runs_uri)
| mv = client.create_model_version(name, model_src, run.info.run_id, description=desc)
| print(f"Name: {mv.name}")
| print(f"Version: {mv.version}")
| print(f"Description: {mv.description}")
| print(f"Status: {mv.status}")
| print(f"Stage: {mv.current_stage}")
|
| .. code-block:: text
| :caption: Output
|
| Name: RandomForestRegression
| Version: 1
| Description: A new version of the model
| Status: READY
| Stage: None
|
| create_prompt(self, name: str, description: str | None = None, tags: dict[str, str] | None = None) -> mlflow.entities.model_registry.prompt.Prompt
| Create a new prompt in the registry.
|
| This method delegates directly to the store, providing full Unity Catalog support
| when used with Unity Catalog registries.
|
| Args:
| name: Name of the prompt.
| description: Optional description of the prompt.
| tags: Optional dictionary of prompt tags.
|
| Returns:
| A Prompt object.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| prompt_info = client.create_prompt(
| name="my_prompt",
| description="A helpful prompt",
| tags={"team": "data-science"},
| )
|
| create_prompt_version(self, name: str, template: str | list[dict[str, typing.Any]], description: str | None = None, tags: dict[str, str] | None = None, response_format: type[pydantic.main.BaseModel] | dict[str, typing.Any] | None = None, model_config: 'PromptModelConfig | dict[str, Any] | None' = None) -> mlflow.entities.model_registry.prompt_version.PromptVersion
| Create a new version of an existing prompt.
|
| This method delegates directly to the store, providing full Unity Catalog support
| when used with Unity Catalog registries.
|
| Args:
| name: Name of the prompt.
| template: The prompt template content for this version.
| description: Optional description of the prompt version.
| tags: Optional dictionary of prompt version tags.
| response_format: Optional Pydantic class or dictionary defining the expected response
| structure. This can be used to specify the schema for structured
| outputs from LLM calls.
| model_config: Optional PromptModelConfig object or dictionary defining the model
| configuration (model name, parameters, etc.) to use when invoking this
| prompt version.
|
| Returns:
| A PromptVersion object.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| prompt_version = client.create_prompt_version(
| name="my_prompt",
| template="Respond as a {{style}} assistant: {{query}}",
| description="Added style parameter",
| tags={"author": "alice"},
| )
|
| create_registered_model(self, name: str, tags: dict[str, typing.Any] | None = None, description: str | None = None, deployment_job_id: str | None = None) -> mlflow.entities.model_registry.registered_model.RegisteredModel
| Create a new registered model in backend store.
|
| Args:
| name: Name of the new model. This is expected to be unique in the backend store.
| tags: A dictionary of key-value pairs that are converted into
| :py:class:`mlflow.entities.model_registry.RegisteredModelTag` objects.
| description: Description of the model.
| deployment_job_id: Optional deployment job ID.
|
| Returns:
| A single object of :py:class:`mlflow.entities.model_registry.RegisteredModel`
| created by backend.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
|
| def print_registered_model_info(rm):
| print(f"name: {rm.name}")
| print(f"tags: {rm.tags}")
| print(f"description: {rm.description}")
|
|
| name = "SocialMediaTextAnalyzer"
| tags = {"nlp.framework": "Spark NLP"}
| desc = "This sentiment analysis model classifies the tone-happy, sad, angry."
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| client = MlflowClient()
| client.create_registered_model(name, tags, desc)
| print_registered_model_info(client.get_registered_model(name))
|
| .. code-block:: text
| :caption: Output
|
| name: SocialMediaTextAnalyzer
| tags: {'nlp.framework': 'Spark NLP'}
| description: This sentiment analysis model classifies the tone-happy, sad, angry.
|
| create_run(self, experiment_id: str, start_time: int | None = None, tags: dict[str, typing.Any] | None = None, run_name: str | None = None) -> mlflow.entities.run.Run
| Create a :py:class:`mlflow.entities.Run` object that can be associated with
| metrics, parameters, artifacts, etc.
| Unlike :py:func:`mlflow.projects.run`, creates objects but does not run code.
| Unlike :py:func:`mlflow.start_run`, does not change the "active run" used by
| :py:func:`mlflow.log_param`.
|
| Args:
| experiment_id: The string ID of the experiment to create a run in.
| start_time: If not provided, use the current timestamp.
| tags: A dictionary of key-value pairs that are converted into
| :py:class:`mlflow.entities.RunTag` objects.
| run_name: The name of this run.
|
| Returns:
| :py:class:`mlflow.entities.Run` that was created.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| # Create a run with a tag under the default experiment (whose id is '0').
| tags = {"engineering": "ML Platform"}
| name = "platform-run-24"
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id, tags=tags, run_name=name)
|
| # Show newly created run metadata info
| print(f"Run tags: {run.data.tags}")
| print(f"Experiment id: {run.info.experiment_id}")
| print(f"Run id: {run.info.run_id}")
| print(f"Run name: {run.info.run_name}")
| print(f"lifecycle_stage: {run.info.lifecycle_stage}")
| print(f"status: {run.info.status}")
|
| .. code-block:: text
| :caption: Output
|
| Run tags: {'engineering': 'ML Platform'}
| Experiment id: 0
| Run id: 65fb9e2198764354bab398105f2e70c1
| Run name: platform-run-24
| lifecycle_stage: active
| status: RUNNING
|
| create_webhook(self, name: str, url: str, events: list[typing.Union[typing.Literal['registered_model.created', 'model_version.created', 'model_version_tag.set', 'model_version_tag.deleted', 'model_version_alias.created', 'model_version_alias.deleted', 'prompt.created', 'prompt_version.created', 'prompt_tag.set', 'prompt_tag.deleted', 'prompt_version_tag.set', 'prompt_version_tag.deleted', 'prompt_alias.created', 'prompt_alias.deleted', 'budget_policy.exceeded'], mlflow.entities.webhook.WebhookEvent]], description: str | None = None, secret: str | None = None, status: str | mlflow.entities.webhook.WebhookStatus | None = None) -> mlflow.entities.webhook.Webhook
| Create a new webhook.
|
| Args:
| name: Name for the webhook.
| url: Webhook endpoint URL.
| events: List of events that trigger this webhook. Can be strings or
| `WebhookEvent` objects.
| description: Optional description of the webhook.
| secret: Optional secret for HMAC signature verification.
| status: Webhook status (defaults to ACTIVE). Can be string or WebhookStatus enum.
| Valid statuses: "ACTIVE", "DISABLED"
|
| Returns:
| A :py:class:`mlflow.entities.webhook.Webhook` object representing the created webhook.
|
| create_workspace(self, name: str, description: str | None = None, default_artifact_root: str | None = None, trace_archival_config: mlflow.entities.workspace.TraceArchivalConfig | None = None) -> mlflow.entities.workspace.Workspace
| Create a new workspace.
|
| Args:
| name: The workspace name (alphanumeric, hyphens, underscores only).
| description: Optional description of the workspace.
| default_artifact_root: Optional artifact root URI; falls back to server default.
| trace_archival_config: Optional Python-side grouping for trace archival settings.
| Use ``TraceArchivalConfig.location`` to set the archival storage URI/root and
| ``TraceArchivalConfig.retention`` to set the archived-trace retention duration such
| as ``30d`` or ``12h``. Leave fields as ``None`` to omit them from the create
| request.
|
| Returns:
| The newly created workspace.
|
| delete_dataset(self, dataset_id: str) -> None
| Delete a dataset and all its records.
|
| Args:
| dataset_id: The ID of the dataset to delete.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Delete a dataset
| client.delete_dataset("dataset_123")
|
| delete_dataset_tag(self, dataset_id: str, key: str) -> None
| Delete a tag from a dataset.
|
| Args:
| dataset_id: The ID of the dataset.
| key: The tag key to delete.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Delete a tag
| client.delete_dataset_tag(dataset_id="dataset123", key="deprecated")
|
| delete_experiment(self, experiment_id: str) -> None
| Delete an experiment from the backend store.
|
| This deletion is a soft-delete, not a permanent deletion. Experiment names can not be
| reused, unless the deleted experiment is permanently deleted by a database admin.
|
| Args:
| experiment_id: The experiment ID returned from ``create_experiment``.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| # Create an experiment with a name that is unique and case sensitive
| client = MlflowClient()
| experiment_id = client.create_experiment("New Experiment")
| client.delete_experiment(experiment_id)
|
| # Examine the deleted experiment details.
| experiment = client.get_experiment(experiment_id)
| print(f"Name: {experiment.name}")
| print(f"Artifact Location: {experiment.artifact_location}")
| print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
|
| .. code-block:: text
| :caption: Output
|
| Name: New Experiment
| Artifact Location: file:///.../mlruns/1
| Lifecycle_stage: deleted
|
| delete_experiment_tag(self, experiment_id: str, key: str) -> None
| Delete a tag from the experiment with the specified ID.
|
| Args:
| experiment_id: String ID of the experiment.
| key: Name of the tag to be deleted.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| # Create an experiment and set its tag
| client = MlflowClient()
| experiment_id = client.create_experiment("Social Media NLP Experiments")
| client.set_experiment_tag(experiment_id, "nlp.framework", "Spark NLP")
|
| # Fetch experiment metadata information, validate that tag is set
| experiment = client.get_experiment(experiment_id)
| assert experiment.tags == {"nlp.framework": "Spark NLP"}
|
| client.delete_experiment_tag(experiment_id, "nlp.framework")
|
| # Fetch experiment metadata information, validate that tag is deleted
| experiment = client.get_experiment(experiment_id)
| assert experiment.tags == {}
|
| delete_logged_model(self, model_id: str) -> None
| Delete the logged model with the specified ID.
|
| Args:
| model_id: ID of the model to delete.
|
| delete_logged_model_tag(self, model_id: str, key: str) -> None
| Delete a tag from the specified logged model.
|
| Args:
| model_id: ID of the model.
| key: Tag key to delete.
|
| delete_mcp_access_endpoint(self, server_name: str, endpoint_id: str) -> None
|
| delete_mcp_server(self, name: str) -> None
|
| delete_mcp_server_alias(self, name: str, alias: str) -> None
|
| delete_mcp_server_tag(self, name: str, key: str) -> None
|
| delete_mcp_server_version(self, name: str, version: str) -> None
|
| delete_mcp_server_version_tag(self, name: str, version: str, key: str) -> None
|
| delete_model_version(self, name: str, version: str) -> None
| Delete model version in backend.
|
| Args:
| name: Name of the containing registered model.
| version: Version number of the model version.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_models_info(mv):
| for m in mv:
| print(f"name: {m.name}")
| print(f"latest version: {m.version}")
| print(f"run_id: {m.run_id}")
| print(f"current_stage: {m.current_stage}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
|
| # Create two runs and log MLflow entities
| with mlflow.start_run() as run1:
| params = {"n_estimators": 3, "random_state": 42}
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| with mlflow.start_run() as run2:
| params = {"n_estimators": 6, "random_state": 42}
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| name = "RandomForestRegression"
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a two versions of the rfr model under the registered model name
| for run_id in [run1.info.run_id, run2.info.run_id]:
| model_uri = f"runs:/{run_id}/sklearn-model"
| mv = client.create_model_version(name, model_uri, run_id)
| print(f"model version {mv.version} created")
|
| print("--")
|
| # Fetch latest version; this will be version 2
| models = client.get_latest_versions(name, stages=["None"])
| print_models_info(models)
| print("--")
|
| # Delete the latest model version 2
| print(f"Deleting model version {mv.version}")
| client.delete_model_version(name, mv.version)
| models = client.get_latest_versions(name, stages=["None"])
| print_models_info(models)
|
| .. code-block:: text
| :caption: Output
|
| model version 1 created
| model version 2 created
| --
| name: RandomForestRegression
| latest version: 2
| run_id: 9881172ef10f4cb08df3ed452c0c362b
| current_stage: None
| --
| Deleting model version 2
| name: RandomForestRegression
| latest version: 1
| run_id: 9165d4f8aa0a4d069550824bdc55caaf
| current_stage: None
|
| delete_model_version_tag(self, name: str, version: str | None = None, key: str | None = None, stage: str | None = None) -> None
| Delete a tag associated with the model version.
|
| When stage is set, tag will be deleted for latest model version of the stage.
| Setting both version and stage parameter will result in error.
|
| Args:
| name: Registered model name.
| version: Registered model version.
| key: Tag key. key is required.
| stage: Registered model stage.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_version_info(mv):
| print(f"Name: {mv.name}")
| print(f"Version: {mv.version}")
| print(f"Tags: {mv.tags}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a new version of the rfr model under the registered model name
| # and delete a tag
| model_uri = f"runs:/{run.info.run_id}/sklearn-model"
| tags = {"t": "1", "t1": "2"}
| mv = client.create_model_version(name, model_uri, run.info.run_id, tags=tags)
| print_model_version_info(mv)
| print("--")
| # using version to delete tag
| client.delete_model_version_tag(name, mv.version, "t")
|
| # using stage to delete tag
| client.delete_model_version_tag(name, key="t1", stage=mv.current_stage)
| mv = client.get_model_version(name, mv.version)
| print_model_version_info(mv)
|
| .. code-block:: text
| :caption: Output
|
| Name: RandomForestRegression
| Version: 1
| Tags: {'t': '1', 't1': '2'}
| --
| Name: RandomForestRegression
| Version: 1
| Tags: {}
|
| delete_prompt(self, name: str) -> None
| Delete a prompt from the registry.
|
| For Unity Catalog registries, this method first checks if any versions exist for the prompt
| and throws an error if undeleted versions are found. All versions must be explicitly
| deleted first before the prompt itself can be deleted.
|
| For other registries, the prompt is deleted normally without version checking.
|
| Args:
| name: Name of the prompt to delete.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # For Unity Catalog, delete all versions first
| if client.get_registry_uri().startswith("databricks-uc"):
| versions = client.search_prompt_versions("my_prompt")
| for version in versions:
| client.delete_prompt_version("my_prompt", version.version)
|
| # Then delete the prompt
| client.delete_prompt("my_prompt")
|
| delete_prompt_alias(self, name: str, alias: str) -> None
| Delete an alias for a :py:class:`Prompt <mlflow.entities.Prompt>`.
|
| Args:
| name: The name of the prompt.
| alias: The alias to delete for the prompt.
|
| delete_prompt_tag(self, name: str, key: str) -> None
| Delete a tag from a prompt.
|
| This method delegates directly to the store, providing full Unity Catalog support
| when used with Unity Catalog registries.
|
| Args:
| name: Name of the prompt.
| key: Tag key to delete.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| client.delete_prompt_tag("my_prompt", "environment")
|
| delete_prompt_version(self, name: str, version: str) -> None
| Delete a specific prompt version.
|
| This method delegates directly to the store, providing full Unity Catalog support
| when used with Unity Catalog registries.
|
| Args:
| name: Name of the prompt.
| version: Version of the prompt to delete.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| client.delete_prompt_version("my_prompt", "1")
|
| delete_prompt_version_tag(self, name: str, version: str | int, key: str) -> None
| Delete a tag from a specific prompt version.
|
| Args:
| name: The name of the prompt.
| version: The version number of the prompt.
| key: The tag key to delete.
|
| delete_registered_model(self, name: str)
| Delete registered model.
| Backend raises exception if a registered model with given name does not exist.
|
| Args:
| name: Name of the registered model to delete.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
|
| def print_registered_models_info(r_models):
| print("--")
| for rm in r_models:
| print(f"name: {rm.name}")
| print(f"tags: {rm.tags}")
| print(f"description: {rm.description}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| client = MlflowClient()
|
| # Register a couple of models with respective names, tags, and descriptions
| for name, tags, desc in [
| ("name1", {"t1": "t1"}, "description1"),
| ("name2", {"t2": "t2"}, "description2"),
| ]:
| client.create_registered_model(name, tags, desc)
|
| # Fetch all registered models
| print_registered_models_info(client.search_registered_models())
|
| # Delete one registered model and fetch again
| client.delete_registered_model("name1")
| print_registered_models_info(client.search_registered_models())
|
| .. code-block:: text
| :caption: Output
|
| --
| name: name1
| tags: {'t1': 't1'}
| description: description1
| name: name2
| tags: {'t2': 't2'}
| description: description2
| --
| name: name2
| tags: {'t2': 't2'}
| description: description2
|
| delete_registered_model_alias(self, name: str, alias: str) -> None
| Delete an alias associated with a registered model.
|
| Args:
| name: Registered model name.
| alias: Name of the alias.
|
| .. code-block:: Python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_info(rm):
| print("--Model--")
| print("name: {}".format(rm.name))
| print("aliases: {}".format(rm.aliases))
|
|
| def print_model_version_info(mv):
| print("--Model Version--")
| print("Name: {}".format(mv.name))
| print("Version: {}".format(mv.version))
| print("Aliases: {}".format(mv.aliases))
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, artifact_path="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
| model = client.get_registered_model(name)
| print_model_info(model)
|
| # Create a new version of the rfr model under the registered model name
| model_uri = "runs:/{}/sklearn-model".format(run.info.run_id)
| mv = client.create_model_version(name, model_uri, run.info.run_id)
| print_model_version_info(mv)
|
| # Set registered model alias
| client.set_registered_model_alias(name, "test-alias", mv.version)
| print()
| print_model_info(model)
| print_model_version_info(mv)
|
| # Delete registered model alias
| client.delete_registered_model_alias(name, "test-alias")
| print()
| print_model_info(model)
| print_model_version_info(mv)
|
| .. code-block:: text
| :caption: Output
|
| --Model--
| name: RandomForestRegression
| aliases: {}
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: []
|
| --Model--
| name: RandomForestRegression
| aliases: {"test-alias": "1"}
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: ["test-alias"]
|
| --Model--
| name: RandomForestRegression
| aliases: {}
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: []
|
| delete_registered_model_tag(self, name: str, key: str) -> None
| Delete a tag associated with the registered model.
|
| Args:
| name: Registered model name.
| key: Registered model tag key.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
|
| def print_registered_models_info(r_models):
| print("--")
| for rm in r_models:
| print(f"name: {rm.name}")
| print(f"tags: {rm.tags}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| client = MlflowClient()
|
| # Register a couple of models with respective names and tags
| for name, tags in [("name1", {"t1": "t1"}), ("name2", {"t2": "t2"})]:
| client.create_registered_model(name, tags)
|
| # Fetch all registered models
| print_registered_models_info(client.search_registered_models())
| # Delete a tag from model `name2`
| client.delete_registered_model_tag("name2", "t2")
| print_registered_models_info(client.search_registered_models())
|
| .. code-block:: text
| :caption: Output
|
| --
| name: name1
| tags: {'t1': 't1'}
| name: name2
| tags: {'t2': 't2'}
| --
| name: name1
| tags: {'t1': 't1'}
| name: name2
| tags: {}
|
| delete_run(self, run_id: str) -> None
| Deletes a run with the given ID.
|
| Args:
| run_id: The unique run id to delete.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| # Create a run under the default experiment (whose id is '0').
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| run_id = run.info.run_id
| print(f"run_id: {run_id}; lifecycle_stage: {run.info.lifecycle_stage}")
| print("--")
| client.delete_run(run_id)
| del_run = client.get_run(run_id)
| print(f"run_id: {run_id}; lifecycle_stage: {del_run.info.lifecycle_stage}")
|
| .. code-block:: text
| :caption: Output
|
| run_id: a61c7a1851324f7094e8d5014c58c8c8; lifecycle_stage: active
| run_id: a61c7a1851324f7094e8d5014c58c8c8; lifecycle_stage: deleted
|
| delete_tag(self, run_id: str, key: str) -> None
| Delete a tag from a run. This is irreversible.
|
| Args:
| run_id: String ID of the run.
| key: Name of the tag.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_run_info(run):
| print(f"run_id: {run.info.run_id}")
| print(f"Tags: {run.data.tags}")
|
|
| # Create a run under the default experiment (whose id is '0').
| client = MlflowClient()
| tags = {"t1": 1, "t2": 2}
| experiment_id = "0"
| run = client.create_run(experiment_id, tags=tags)
| print_run_info(run)
| print("--")
|
| # Delete tag and fetch updated info
| client.delete_tag(run.info.run_id, "t1")
| run = client.get_run(run.info.run_id)
| print_run_info(run)
|
| .. code-block:: text
| :caption: Output
|
| run_id: b7077267a59a45d78cd9be0de4bc41f5
| Tags: {'t2': '2', 't1': '1'}
| --
| run_id: b7077267a59a45d78cd9be0de4bc41f5
| Tags: {'t2': '2'}
|
| delete_trace_tag(self, trace_id: str, key: str) -> None
| .. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
|
| Delete a tag on the trace with the given trace ID.
|
| The trace can be an active one or the one that has already ended and recorded in the
| backend. Below is an example of deleting a tag on an active trace. You can replace the
| ``trace_id`` parameter to delete a tag on an already ended trace.
|
| .. code-block:: python
| :test:
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| root_span = client.start_trace("my_trace", tags={"key": "value"})
| client.delete_trace_tag(root_span.trace_id, "key")
| client.end_trace(root_span.trace_id)
|
| Args:
| trace_id: The ID of the trace to delete the tag from.
| key: The string key of the tag. Must be at most 250 characters long, otherwise
| it will be truncated when stored.
|
| delete_traces(self, experiment_id: str, max_timestamp_millis: int | None = None, max_traces: int | None = None, trace_ids: list[str] | None = None) -> int
| Delete traces based on the specified criteria.
|
| - Either `max_timestamp_millis` or `trace_ids` must be specified, but not both.
| - `max_traces` can't be specified if `trace_ids` is specified.
|
| Args:
| experiment_id: ID of the associated experiment.
| max_timestamp_millis: The maximum timestamp in milliseconds since the UNIX epoch for
| deleting traces. Traces older than or equal to this timestamp will be deleted.
| max_traces: The maximum number of traces to delete. If max_traces is specified, and
| it is less than the number of traces that would be deleted based on the
| max_timestamp_millis, the oldest traces will be deleted first.
| trace_ids: A set of trace IDs to delete.
|
| Returns:
| The number of traces deleted.
|
| Example:
|
| .. code-block:: python
| :test:
|
| import mlflow
| import time
|
| client = mlflow.MlflowClient()
|
| # Delete all traces in the experiment
| client.delete_traces(
| experiment_id="0", max_timestamp_millis=time.time_ns() // 1_000_000
| )
|
| # Delete traces based on max_timestamp_millis and max_traces
| # Older traces will be deleted first.
| some_timestamp = time.time_ns() // 1_000_000
| client.delete_traces(
| experiment_id="0", max_timestamp_millis=some_timestamp, max_traces=2
| )
|
| # Delete traces based on trace_ids
| client.delete_traces(experiment_id="0", trace_ids=["id_1", "id_2"])
|
| delete_webhook(self, webhook_id: str) -> None
| Delete a webhook.
|
| Args:
| webhook_id: Webhook ID to delete.
|
| Returns:
| None
|
| delete_workspace(self, name: str, mode: str = <WorkspaceDeletionMode.RESTRICT: 'RESTRICT'>) -> None
| Delete an existing workspace.
|
| Args:
| name: Name of the workspace to delete.
| mode: Deletion mode — ``"SET_DEFAULT"``, ``"CASCADE"``, or ``"RESTRICT"``.
|
| detach_prompt_from_run(self, run_id: str, prompt_uri: str) -> None
| Detach a prompt registered within the MLflow Prompt Registry from an MLflow Run.
|
| Args:
| run_id: The ID of the run to log the prompt to.
| prompt_uri: The prompt URI in the format "prompts:/name/version".
|
| download_artifacts(self, run_id: str, path: str, dst_path: str | None = None) -> str
| Download an artifact file or directory from a run to a local directory if applicable,
| and return a local path for it.
|
| Args:
| run_id: The run to download artifacts from.
| path: Relative source path to the desired artifact.
| dst_path: Absolute path of the local filesystem destination directory to which to
| download the specified artifacts. This directory must already exist.
| If unspecified, the artifacts will either be downloaded to a new
| uniquely-named directory on the local filesystem or will be returned
| directly in the case of the LocalArtifactRepository.
|
| Returns:
| Local path of desired artifact.
|
| .. code-block:: python
| :caption: Example
|
| import os
| import mlflow
| from mlflow import MlflowClient
|
| features = "rooms, zipcode, median_price, school_rating, transport"
| with open("features.txt", "w") as f:
| f.write(features)
|
| # Log artifacts
| with mlflow.start_run() as run:
| mlflow.log_artifact("features.txt", artifact_path="features")
|
| # Download artifacts
| client = MlflowClient()
| local_dir = "/tmp/artifact_downloads"
| if not os.path.exists(local_dir):
| os.mkdir(local_dir)
| local_path = client.download_artifacts(run.info.run_id, "features", local_dir)
| print(f"Artifacts downloaded in: {local_path}")
| print(f"Artifacts: {os.listdir(local_path)}")
|
| .. code-block:: text
| :caption: Output
|
| Artifacts downloaded in: /tmp/artifact_downloads/features
| Artifacts: ['features.txt']
|
| end_span(self, trace_id: str, span_id: str, outputs: typing.Any | None = None, attributes: dict[str, typing.Any] | None = None, status: mlflow.entities.span_status.SpanStatus | str = 'OK', end_time_ns: int | None = None)
| .. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
|
| End the span with the given trace ID and span ID.
|
| Args:
| trace_id: The ID of the trace to end.
| span_id: The ID of the span to end.
| outputs: Outputs to set on the span.
| attributes: A dictionary of attributes to set on the span. If the span already has
| attributes, the new attributes will be merged with the existing ones. If the same
| key already exists, the new value will overwrite the old one.
| status: The status of the span. This can be a
| :py:class:`SpanStatus <mlflow.entities.SpanStatus>` object or a string
| representing the status code defined in
| :py:class:`SpanStatusCode <mlflow.entities.SpanStatusCode>`
| e.g. ``"OK"``, ``"ERROR"``. The default status is OK.
| end_time_ns: The end time of the span in nano seconds since the UNIX epoch.
| If not provided, the current time will be used.
|
| end_trace(self, trace_id: str, outputs: typing.Any | None = None, attributes: dict[str, typing.Any] | None = None, status: mlflow.entities.span_status.SpanStatus | str = 'OK', end_time_ns: int | None = None)
| .. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
|
| End the trace with the given trace ID. This will end the root span of the trace and
| log the trace to the backend if configured.
|
| If any of children spans are not ended, they will be ended forcefully with the status
| ``TRACE_STATUS_UNSPECIFIED``. If the trace is already ended, this method will have
| no effect.
|
| Args:
| trace_id: The ID of the trace to end.
| outputs: Outputs to set on the trace.
| attributes: A dictionary of attributes to set on the trace. If the trace already
| has attributes, the new attributes will be merged with the existing ones.
| If the same key already exists, the new value will overwrite the old one.
| status: The status of the trace. This can be a
| :py:class:`SpanStatus <mlflow.entities.SpanStatus>` object or a string
| representing the status code defined in
| :py:class:`SpanStatusCode <mlflow.entities.SpanStatusCode>`
| e.g. ``"OK"``, ``"ERROR"``. The default status is OK.
| end_time_ns: The end time of the trace in nanoseconds since the UNIX epoch.
|
| finalize_logged_model(self, model_id: str, status: Union[Literal['READY', 'FAILED'], mlflow.entities.logged_model_status.LoggedModelStatus]) -> mlflow.entities.logged_model.LoggedModel
| Finalize a model by updating its status.
|
| Args:
| model_id: ID of the model to finalize.
| status: Final status to set on the model.
|
| Returns:
| The updated model.
|
| get_dataset(self, dataset_id: str) -> mlflow.entities.evaluation_dataset.EvaluationDataset
| Get a dataset by ID.
|
| Args:
| dataset_id: The ID of the dataset to retrieve.
|
| Returns:
| The EvaluationDataset object.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Get a dataset by ID (assuming it exists)
| dataset = client.get_dataset("dataset_123")
|
| # Access records (lazy loaded)
| df = dataset.to_df()
|
| get_experiment(self, experiment_id: str) -> mlflow.entities.experiment.Experiment
| Retrieve an experiment by experiment_id from the backend store
|
| Args:
| experiment_id: The experiment ID returned from ``create_experiment``.
|
| Returns:
| :py:class:`mlflow.entities.Experiment`
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| exp_id = client.create_experiment("Experiment")
| experiment = client.get_experiment(exp_id)
|
| # Show experiment info
| print(f"Name: {experiment.name}")
| print(f"Experiment ID: {experiment.experiment_id}")
| print(f"Artifact Location: {experiment.artifact_location}")
| print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
|
| .. code-block:: text
| :caption: Output
|
| Name: Experiment
| Experiment ID: 1
| Artifact Location: file:///.../mlruns/1
| Lifecycle_stage: active
|
| get_experiment_by_name(self, name: str) -> mlflow.entities.experiment.Experiment | None
| Retrieve an experiment by experiment name from the backend store
|
| Args:
| name: The experiment name, which is case sensitive.
|
| Returns:
| An instance of :py:class:`mlflow.entities.Experiment`
| if an experiment with the specified name exists, otherwise None.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| # Case-sensitive name
| client = MlflowClient()
| experiment = client.get_experiment_by_name("Default")
| # Show experiment info
| print(f"Name: {experiment.name}")
| print(f"Experiment ID: {experiment.experiment_id}")
| print(f"Artifact Location: {experiment.artifact_location}")
| print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
|
| .. code-block:: text
| :caption: Output
|
| Name: Default
| Experiment ID: 0
| Artifact Location: file:///.../mlruns/0
| Lifecycle_stage: active
|
| get_latest_mcp_server_version(self, name: str) -> mlflow.entities.mcp_server_version.MCPServerVersion
|
| get_latest_versions(self, name: str, stages: list[str] | None = None) -> list[mlflow.entities.model_registry.model_version.ModelVersion]
| .. Warning:: ``mlflow.tracking.client.MlflowClient.get_latest_versions`` is deprecated since 2.9.0. Model registry stages will be removed in a future major release. To learn more about the deprecation of model registry stages, see our migration guide here: https://mlflow.org/docs/latest/model-registry.html#migrating-from-stages
|
| Latest version models for each requests stage. If no ``stages`` provided, returns the
| latest version for each stage.
|
| Args:
| name: Name of the registered model from which to get the latest versions.
| stages: List of desired stages. If input list is None, return latest versions for
| for ALL_STAGES.
|
| Returns:
| List of :py:class:`mlflow.entities.model_registry.ModelVersion` objects.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_models_info(mv):
| for m in mv:
| print(f"name: {m.name}")
| print(f"latest version: {m.version}")
| print(f"run_id: {m.run_id}")
| print(f"current_stage: {m.current_stage}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| # Create two runs Log MLflow entities
| with mlflow.start_run() as run1:
| params = {"n_estimators": 3, "random_state": 42}
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
| with mlflow.start_run() as run2:
| params = {"n_estimators": 6, "random_state": 42}
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
| # Register model name in the model registry
| name = "RandomForestRegression"
| client = MlflowClient()
| client.create_registered_model(name)
| # Create a two versions of the rfr model under the registered model name
| for run_id in [run1.info.run_id, run2.info.run_id]:
| model_uri = f"runs:/{run_id}/sklearn-model"
| mv = client.create_model_version(name, model_uri, run_id)
| print(f"model version {mv.version} created")
| # Fetch latest version; this will be version 2
| print("--")
| print_models_info(client.get_latest_versions(name, stages=["None"]))
|
| .. code-block:: text
| :caption: Output
|
| model version 1 created
| model version 2 created
| --
| name: RandomForestRegression
| latest version: 2
| run_id: 31165664be034dc698c52a4bdeb71663
| current_stage: None
|
| get_logged_model(self, model_id: str) -> mlflow.entities.logged_model.LoggedModel
| Fetch the logged model with the specified ID.
|
| Args:
| model_id: ID of the model to fetch.
|
| Returns:
| The fetched model.
|
| get_mcp_access_endpoint(self, server_name: str, endpoint_id: str) -> mlflow.entities.mcp_access_endpoint.MCPAccessEndpoint
|
| get_mcp_server(self, name: str) -> mlflow.entities.mcp_server.MCPServer
|
| get_mcp_server_version(self, name: str, version: str) -> mlflow.entities.mcp_server_version.MCPServerVersion
|
| get_mcp_server_version_by_alias(self, name: str, alias: str) -> mlflow.entities.mcp_server_version.MCPServerVersion
|
| get_metric_history(self, run_id: str, key: str) -> list[mlflow.entities.metric.Metric]
| Return a list of metric objects corresponding to all values logged for a given metric.
|
| Args:
| run_id: Unique identifier for run.
| key: Metric name within the run.
|
| Returns:
| A list of :py:class:`mlflow.entities.Metric` entities if logged, else empty list.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_metric_info(history):
| for m in history:
| print(f"name: {m.key}")
| print(f"value: {m.value}")
| print(f"step: {m.step}")
| print(f"timestamp: {m.timestamp}")
| print("--")
|
|
| # Create a run under the default experiment (whose id is "0"). Since this is low-level
| # CRUD operation, the method will create a run. To end the run, you'll have
| # to explicitly end it.
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| print(f"run_id: {run.info.run_id}")
| print("--")
|
| # Log couple of metrics, update their initial value, and fetch each
| # logged metrics' history.
| for k, v in [("m1", 1.5), ("m2", 2.5)]:
| client.log_metric(run.info.run_id, k, v, step=0)
| client.log_metric(run.info.run_id, k, v + 1, step=1)
| print_metric_info(client.get_metric_history(run.info.run_id, k))
| client.set_terminated(run.info.run_id)
|
| .. code-block:: text
| :caption: Output
|
| run_id: c360d15714994c388b504fe09ea3c234
| --
| name: m1
| value: 1.5
| step: 0
| timestamp: 1603423788607
| --
| name: m1
| value: 2.5
| step: 1
| timestamp: 1603423788608
| --
| name: m2
| value: 2.5
| step: 0
| timestamp: 1603423788609
| --
| name: m2
| value: 3.5
| step: 1
| timestamp: 1603423788610
| --
|
| get_model_version(self, name: str, version: str) -> mlflow.entities.model_registry.model_version.ModelVersion
| Converts the docstring args and returns to google style.
|
| Args:
| name: Name of the containing registered model.
| version: Version number as an integer of the model version.
|
| Returns:
| A single :py:class:`mlflow.entities.model_registry.ModelVersion` object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
|
| # Create two runs Log MLflow entities
| with mlflow.start_run() as run1:
| params = {"n_estimators": 3, "random_state": 42}
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| with mlflow.start_run() as run2:
| params = {"n_estimators": 6, "random_state": 42}
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| name = "RandomForestRegression"
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a two versions of the rfr model under the registered model name
| for run_id in [run1.info.run_id, run2.info.run_id]:
| model_uri = f"runs:/{run_id}/sklearn-model"
| mv = client.create_model_version(name, model_uri, run_id)
| print(f"model version {mv.version} created")
| print("--")
|
| # Fetch the last version; this will be version 2
| mv = client.get_model_version(name, mv.version)
| print(f"Name: {mv.name}")
| print(f"Version: {mv.version}")
|
| .. code-block:: text
| :caption: Output
|
| model version 1 created
| model version 2 created
| --
| Name: RandomForestRegression
| Version: 2
|
| get_model_version_by_alias(self, name: str, alias: str) -> mlflow.entities.model_registry.model_version.ModelVersion
| Get the model version instance by name and alias.
|
| Args:
| name: Registered model name.
| alias: Name of the alias.
|
| Returns:
| A single :py:class:`mlflow.entities.model_registry.ModelVersion` object.
|
| .. code-block:: Python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_info(rm):
| print("--Model--")
| print("name: {}".format(rm.name))
| print("aliases: {}".format(rm.aliases))
|
|
| def print_model_version_info(mv):
| print("--Model Version--")
| print("Name: {}".format(mv.name))
| print("Version: {}".format(mv.version))
| print("Aliases: {}".format(mv.aliases))
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, artifact_path="sklearn-model", signature=signature)
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
| model = client.get_registered_model(name)
| print_model_info(model)
| # Create a new version of the rfr model under the registered model name
| model_uri = "runs:/{}/sklearn-model".format(run.info.run_id)
| mv = client.create_model_version(name, model_uri, run.info.run_id)
| print_model_version_info(mv)
| # Set registered model alias
| client.set_registered_model_alias(name, "test-alias", mv.version)
| print()
| print_model_info(model)
| print_model_version_info(mv)
| # Get model version by alias
| alias_mv = client.get_model_version_by_alias(name, "test-alias")
| print()
| print_model_version_info(alias_mv)
|
| .. code-block:: text
| :caption: Output
|
| --Model--
| name: RandomForestRegression
| aliases: {}
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: []
| --Model--
| name: RandomForestRegression
| aliases: {"test-alias": "1"}
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: ["test-alias"]
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: ["test-alias"]
|
| get_model_version_download_uri(self, name: str, version: str) -> str
| Get the download location in Model Registry for this model version.
|
| Args:
| name: Name of the containing registered model.
| version: Version number as an integer of the model version.
|
| Returns:
| A single URI location that allows reads for downloading.
|
| .. code-block:: python
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a new version of the rfr model under the registered model name
| model_uri = f"runs:/{run.info.run_id}/sklearn-model"
| mv = client.create_model_version(name, model_uri, run.info.run_id)
| artifact_uri = client.get_model_version_download_uri(name, mv.version)
| print(f"Download URI: {artifact_uri}")
|
| .. code-block:: text
|
| Download URI: runs:/027d7bbe81924c5a82b3e4ce979fcab7/sklearn-model
|
| get_model_version_stages(self, name: str, version: str) -> list[str]
| .. Warning:: ``mlflow.tracking.client.MlflowClient.get_model_version_stages`` is deprecated since 2.9.0. Model registry stages will be removed in a future major release. To learn more about the deprecation of model registry stages, see our migration guide here: https://mlflow.org/docs/latest/model-registry.html#migrating-from-stages
|
| This is a docstring. Here is info.
|
| Returns:
| A list of valid stages.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a new version of the rfr model under the registered model name
| # fetch valid stages
| model_uri = f"runs:/{run.info.run_id}/models/sklearn-model"
| mv = client.create_model_version(name, model_uri, run.info.run_id)
| stages = client.get_model_version_stages(name, mv.version)
| print(f"Model list of valid stages: {stages}")
|
| .. code-block:: text
| :caption: Output
|
| Model list of valid stages: ['None', 'Staging', 'Production', 'Archived']
|
| get_parent_run(self, run_id: str) -> mlflow.entities.run.Run | None
| Gets the parent run for the given run id if one exists.
|
| Args:
| run_id: Unique identifier for the child run.
|
| Returns:
| A single :py:class:`mlflow.entities.Run` object, if the parent run exists. Otherwise,
| returns None.
|
| .. code-block:: python
| :test:
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
| # Create nested runs
| with mlflow.start_run():
| with mlflow.start_run(nested=True) as child_run:
| child_run_id = child_run.info.run_id
|
| client = MlflowClient()
| parent_run = client.get_parent_run(child_run_id)
|
| print(f"child_run_id: {child_run_id}")
| print(f"parent_run_id: {parent_run.info.run_id}")
|
| .. code-block:: text
| :caption: Output
|
| child_run_id: 7d175204675e40328e46d9a6a5a7ee6a
| parent_run_id: 8979459433a24a52ab3be87a229a9cdf
|
| get_prompt(self, name: str) -> mlflow.entities.model_registry.prompt.Prompt | None
| Get prompt metadata by name.
|
| Args:
| name: Name of the prompt.
|
| Returns:
| A Prompt object containing prompt metadata, or None if not found.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| prompt = client.get_prompt("my_prompt")
| if prompt:
| print(f"Prompt: {prompt.name}")
| print(f"Description: {prompt.description}")
|
| get_prompt_version(self, name: str, version: str | int) -> mlflow.entities.model_registry.prompt_version.PromptVersion | None
| Get a specific prompt version.
|
| This method delegates directly to the store, providing full Unity Catalog support
| when used with Unity Catalog registries.
|
| Args:
| name: Name of the prompt.
| version: Version of the prompt (number or alias).
|
| Returns:
| A PromptVersion object with the specific version content, or None if not found.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| prompt_version = client.get_prompt_version("my_prompt", "1")
| prompt_alias = client.get_prompt_version("my_prompt", "production")
|
| get_prompt_version_by_alias(self, name: str, alias: str) -> mlflow.entities.model_registry.prompt_version.PromptVersion
| Get a prompt version by alias.
|
| This method delegates directly to the store, providing full Unity Catalog support
| when used with Unity Catalog registries.
|
| Args:
| name: Name of the prompt.
| alias: Alias of the prompt version.
|
| Returns:
| A PromptVersion object.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| prompt_version = client.get_prompt_version_by_alias("my_prompt", "production")
|
| get_registered_model(self, name: str) -> mlflow.entities.model_registry.registered_model.RegisteredModel
| Get a registered model.
|
| Args:
| name: Name of the registered model to get.
|
| Returns:
| A single :py:class:`mlflow.entities.model_registry.RegisteredModel` object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
|
| def print_model_info(rm):
| print("--")
| print(f"name: {rm.name}")
| print(f"tags: {rm.tags}")
| print(f"description: {rm.description}")
|
|
| name = "SocialMediaTextAnalyzer"
| tags = {"nlp.framework": "Spark NLP"}
| desc = "This sentiment analysis model classifies the tone-happy, sad, angry."
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| client = MlflowClient()
| # Create and fetch the registered model
| client.create_registered_model(name, tags, desc)
| model = client.get_registered_model(name)
| print_model_info(model)
|
| .. code-block:: text
| :caption: Output
|
| --
| name: SocialMediaTextAnalyzer
| tags: {'nlp.framework': 'Spark NLP'}
| description: This sentiment analysis model classifies the tone-happy, sad, angry.
|
| get_run(self, run_id: str) -> mlflow.entities.run.Run
| Fetch the run from backend store. The resulting :py:class:`Run <mlflow.entities.Run>`
| contains a collection of run metadata -- :py:class:`RunInfo <mlflow.entities.RunInfo>`,
| as well as a collection of run parameters, tags, and metrics --
| :py:class:`RunData <mlflow.entities.RunData>`. It also contains a collection of run
| inputs (experimental), including information about datasets used by the run --
| :py:class:`RunInputs <mlflow.entities.RunInputs>`. In the case where multiple metrics with
| the same key are logged for the run, the :py:class:`RunData <mlflow.entities.RunData>`
| contains the most recently logged value at the largest step for each metric.
|
| Args:
| run_id: Unique identifier for the run.
|
| Returns:
| A single :py:class:`mlflow.entities.Run` object, if the run exists. Otherwise,
| raises an exception.
|
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
| with mlflow.start_run() as run:
| mlflow.log_param("p", 0)
|
| # The run has finished since we have exited the with block
| # Fetch the run
| client = MlflowClient()
| run = client.get_run(run.info.run_id)
| print(f"run_id: {run.info.run_id}")
| print(f"params: {run.data.params}")
| print(f"status: {run.info.status}")
|
| .. code-block:: text
| :caption: Output
|
| run_id: e36b42c587a1413ead7c3b6764120618
| params: {'p': '0'}
| status: FINISHED
|
| get_trace(self, trace_id: str, display=True, flush: bool = False) -> mlflow.entities.trace.Trace
| .. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
|
| Get the trace matching the specified ``trace_id``.
|
| Args:
| trace_id: String ID of the trace to fetch.
| display: If ``True``, display the trace on the notebook.
| flush: If ``True``, flush any pending async trace writes before fetching.
| Useful in tests or scripts where async logging may not have completed.
| Default to ``False``.
|
| Returns:
| The retrieved :py:class:`Trace <mlflow.entities.Trace>`.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| trace_id = "12345678"
| trace = client.get_trace(trace_id)
|
| get_webhook(self, webhook_id: str) -> mlflow.entities.webhook.Webhook
| Get webhook instance by ID.
|
| Args:
| webhook_id: Webhook ID.
|
| Returns:
| A :py:class:`mlflow.entities.webhook.Webhook` object.
|
| get_workspace(self, name: str) -> mlflow.entities.workspace.Workspace
| Return metadata for the specified workspace.
|
| get_workspace_store_uri(self) -> str
| Return the resolved workspace provider URI. This value is always non-null because
| `resolve_workspace_store_uri()` falls back to the tracking URI when no workspace URI is
| explicitly provided.
|
| link_prompt_version_to_model(self, name: str, version: str, model_id: str) -> None
| Link a prompt version to a model.
|
| Args:
| name: The name of the prompt.
| version: The version of the prompt.
| model_id: The ID of the model to link the prompt version to.
|
| link_prompt_version_to_run(self, run_id: str, prompt: str | mlflow.entities.model_registry.prompt_version.PromptVersion) -> None
| Link a prompt registered within the MLflow Prompt Registry with an MLflow Run.
|
| .. warning::
|
| This API is not thread-safe. If you are linking prompts from multiple threads,
| consider using a lock to ensure that only one thread links a prompt to a run at a time.
|
| Args:
| run_id: The ID of the run to link the prompt to.
| prompt: A Prompt object or the prompt URI in the format "prompts:/name/version".
|
| link_prompt_versions_to_trace(self, prompt_versions: list[mlflow.entities.model_registry.prompt_version.PromptVersion], trace_id: str) -> None
| Link multiple prompt versions to a trace.
|
| Args:
| prompt_versions: List of PromptVersion objects to link.
| trace_id: Trace ID to link to each prompt version.
|
| Example:
| .. code-block:: python
|
| import mlflow
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Get prompt versions and link to trace
| prompt_v1 = client.get_prompt_version("my_prompt", "1")
| prompt_v2 = client.get_prompt_version("another_prompt", "2")
|
| client.link_prompt_versions_to_trace(
| prompt_versions=[prompt_v1, prompt_v2],
| trace_id="trace_123",
| )
|
| link_traces_to_run(self, trace_ids: list[str], run_id: str) -> None
| Link multiple traces to a run by creating entity associations.
|
| Args:
| trace_ids: List of trace IDs to link to the run. Maximum 100 traces allowed.
| run_id: ID of the run to link traces to.
|
| Example:
| .. code-block:: python
|
| import mlflow
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Link multiple traces to a run
| client.link_traces_to_run(
| trace_ids=["trace_123", "trace_456", "trace_789"],
| run_id="run_abc",
| )
|
| list_artifacts(self, run_id: str, path=None) -> list[mlflow.entities.file_info.FileInfo]
| List the artifacts for a run.
|
| Args:
| run_id: The run to list artifacts from.
| path: The run's relative artifact path to list from. By default it is set to None
| or the root artifact path.
|
| Returns:
| List of :py:class:`mlflow.entities.FileInfo`
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_artifact_info(artifact):
| print(f"artifact: {artifact.path}")
| print(f"is_dir: {artifact.is_dir}")
| print(f"size: {artifact.file_size}")
|
|
| features = "rooms zipcode, median_price, school_rating, transport"
| labels = "price"
|
| # Create a run under the default experiment (whose id is '0').
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
|
| # Create some artifacts and log under the above run
| for file, content in [("features", features), ("labels", labels)]:
| with open(f"{file}.txt", "w") as f:
| f.write(content)
| client.log_artifact(run.info.run_id, f"{file}.txt")
|
| # Fetch the logged artifacts
| artifacts = client.list_artifacts(run.info.run_id)
| for artifact in artifacts:
| print_artifact_info(artifact)
| client.set_terminated(run.info.run_id)
|
| .. code-block:: text
| :caption: Output
|
| artifact: features.txt
| is_dir: False
| size: 53
| artifact: labels.txt
| is_dir: False
| size: 5
|
| list_logged_model_artifacts(self, model_id: str, path: str | None = None) -> list[mlflow.entities.file_info.FileInfo]
|
| list_logged_prompts(self, run_id: str) -> list[mlflow.entities.model_registry.prompt_version.PromptVersion]
| List all prompts associated with an MLflow Run.
|
| Args:
| run_id: The ID of the run to list the prompts for.
|
| Returns:
| A list of :py:class:`Prompt <mlflow.entities.Prompt>` objects associated with the run.
|
| list_webhooks(self, max_results: int | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.webhook.Webhook]
| List webhooks.
|
| Args:
| max_results: Maximum number of webhooks to return.
| page_token: Token specifying the next page of results.
|
| Returns:
| A :py:class:`mlflow.store.entities.paged_list.PagedList` of Webhook objects.
|
| list_workspaces(self) -> list[mlflow.entities.workspace.Workspace]
| Return the list of workspaces available to the current user.
|
| load_prompt(self, name_or_uri: str, version: str | int | None = None, allow_missing: bool = False, cache_ttl_seconds: float | None = None) -> mlflow.entities.model_registry.prompt_version.PromptVersion | None
| Load a :py:class:`Prompt <mlflow.entities.Prompt>` from the MLflow Prompt Registry.
|
| The prompt can be specified by name and version, or by URI.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient(registry_uri="sqlite:///prompt_registry.db")
|
| # Load a specific version of the prompt by name and version
| prompt = client.load_prompt("my_prompt", version=1)
|
| # Load a specific version of the prompt by URI
| prompt = client.load_prompt("prompts:/my_prompt/1")
|
| Args:
| name_or_uri: The name of the prompt, or the URI in the format "prompts:/name/version".
| version: The version of the prompt (required when using name, not allowed when
| using URI).
| allow_missing: If True, return None instead of raising Exception if the specified prompt
| is not found.
| cache_ttl_seconds: Time-to-live for caching the prompt in seconds. If None, uses
| the value from `MLFLOW_ALIAS_PROMPT_CACHE_TTL_SECONDS` environment variable for
| alias-based prompts (default 60), and the value from
| `MLFLOW_VERSION_PROMPT_CACHE_TTL_SECONDS` environment variable for version-based
| prompts (default None, no TTL). Set to 0 to disable caching.
|
| load_table(self, experiment_id: str, artifact_file: str, run_ids: list[str] | None = None, extra_columns: list[str] | None = None) -> 'pandas.DataFrame'
| Load a table from MLflow Tracking as a pandas.DataFrame. The table is loaded from the
| specified artifact_file in the specified run_ids. The extra_columns are columns that
| are not in the table but are augmented with run information and added to the DataFrame.
|
| Args:
| experiment_id: The experiment ID to load the table from.
| artifact_file: The run-relative artifact file path in posixpath format to which
| table to load (e.g. "dir/file.json").
| run_ids: Optional list of run_ids to load the table from. If no run_ids are
| specified, the table is loaded from all runs in the current experiment.
| extra_columns: Optional list of extra columns to add to the returned DataFrame
| For example, if extra_columns=["run_id"], then the returned DataFrame
| will have a column named run_id.
|
| Returns:
| pandas.DataFrame containing the loaded table if the artifact exists
| or else throw a MlflowException.
|
| .. code-block:: python
| :test:
| :caption: Example with passing run_ids
|
| import mlflow
| import pandas as pd
| from mlflow import MlflowClient
|
| table_dict = {
| "inputs": ["What is MLflow?", "What is Databricks?"],
| "outputs": ["MLflow is ...", "Databricks is ..."],
| "toxicity": [0.0, 0.0],
| }
| df = pd.DataFrame.from_dict(table_dict)
| client = MlflowClient()
| run = client.create_run(experiment_id="0")
| client.log_table(run.info.run_id, data=df, artifact_file="qabot_eval_results.json")
| loaded_table = client.load_table(
| experiment_id="0",
| artifact_file="qabot_eval_results.json",
| run_ids=[
| run.info.run_id,
| ],
| # Append a column containing the associated run ID for each row
| extra_columns=["run_id"],
| )
|
| .. code-block:: python
| :test:
| :caption: Example with passing no run_ids
|
| # Loads the table with the specified name for all runs in the given
| # experiment and joins them together
| import mlflow
| import pandas as pd
| from mlflow import MlflowClient
|
| table_dict = {
| "inputs": ["What is MLflow?", "What is Databricks?"],
| "outputs": ["MLflow is ...", "Databricks is ..."],
| "toxicity": [0.0, 0.0],
| }
| df = pd.DataFrame.from_dict(table_dict)
| client = MlflowClient()
| run = client.create_run(experiment_id="0")
| client.log_table(run.info.run_id, data=df, artifact_file="qabot_eval_results.json")
| loaded_table = client.load_table(
| experiment_id="0",
| artifact_file="qabot_eval_results.json",
| # Append the run ID and the parent run ID to the table
| extra_columns=["run_id"],
| )
|
| log_artifact(self, run_id, local_path, artifact_path=None) -> None
| Write a local file or directory to the remote ``artifact_uri``.
|
| Args:
| run_id: String ID of run.
| local_path: Path to the file or directory to write.
| artifact_path: If provided, the directory in ``artifact_uri`` to write to.
|
| .. code-block:: python
| :caption: Example
|
| import tempfile
| from pathlib import Path
|
| from mlflow import MlflowClient
|
| # Create a run under the default experiment (whose id is '0').
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
|
| # log and fetch the artifact
| with tempfile.TemporaryDirectory() as tmp_dir:
| path = Path(tmp_dir, "features.txt")
| path.write_text(features)
| client.log_artifact(run.info.run_id, path)
|
| artifacts = client.list_artifacts(run.info.run_id)
| for artifact in artifacts:
| print(f"artifact: {artifact.path}")
| print(f"is_dir: {artifact.is_dir}")
| client.set_terminated(run.info.run_id)
|
| .. code-block:: text
| :caption: Output
|
| artifact: features.txt
| is_dir: False
|
| log_artifacts(self, run_id: str, local_dir: str, artifact_path: str | None = None) -> None
| Write a directory of files to the remote ``artifact_uri``.
|
| Args:
| run_id: String ID of run.
| local_dir: Path to the directory of files to write.
| artifact_path: If provided, the directory in ``artifact_uri`` to write to.
|
| .. code-block:: python
| :caption: Example
|
| import json
| import tempfile
| from pathlib import Path
|
| # Create some artifacts data to preserve
| features = "rooms, zipcode, median_price, school_rating, transport"
| data = {"state": "TX", "Available": 25, "Type": "Detached"}
| with tempfile.TemporaryDirectory() as tmp_dir:
| tmp_dir = Path(tmp_dir)
| with (tmp_dir / "data.json").open("w") as f:
| json.dump(data, f, indent=2)
| with (tmp_dir / "features.json").open("w") as f:
| f.write(features)
|
| # Create a run under the default experiment (whose id is '0'), and log
| # all files in "data" to root artifact_uri/states
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| client.log_artifacts(run.info.run_id, tmp_dir, artifact_path="states")
|
| artifacts = client.list_artifacts(run.info.run_id)
| for artifact in artifacts:
| print(f"artifact: {artifact.path}")
| print(f"is_dir: {artifact.is_dir}")
| client.set_terminated(run.info.run_id)
|
| .. code-block:: text
| :caption: Output
|
| artifact: states
| is_dir: True
|
| log_batch(self, run_id: str, metrics: Sequence[mlflow.entities.metric.Metric] = (), params: Sequence[mlflow.entities.param.Param] = (), tags: Sequence[mlflow.entities.run_tag.RunTag] = (), synchronous: bool | None = None) -> mlflow.utils.async_logging.run_operations.RunOperations | None
| Log multiple metrics, params, and/or tags.
|
| Args:
| run_id: String ID of the run
| metrics: If provided, List of Metric(key, value, timestamp) instances.
| params: If provided, List of Param(key, value) instances.
| tags: If provided, List of RunTag(key, value) instances.
| synchronous: *Experimental* If True, blocks until the metric is logged successfully.
| If False, logs the metric asynchronously and returns a future representing the
| logging operation. If None, read from environment variable
| `MLFLOW_ENABLE_ASYNC_LOGGING`, which defaults to False if not set.
|
| Raises:
| mlflow.MlflowException: If any errors occur.
|
| Returns:
| When `synchronous=True` or None, returns None. When `synchronous=False`, returns an
| :py:class:`mlflow.utils.async_logging.run_operations.RunOperations` instance that
| represents future for logging operation.
|
| .. code-block:: python
| :caption: Example
|
| import time
|
| from mlflow import MlflowClient
| from mlflow.entities import Metric, Param, RunTag
|
|
| def print_run_info(r):
| print(f"run_id: {r.info.run_id}")
| print(f"params: {r.data.params}")
| print(f"metrics: {r.data.metrics}")
| print(f"tags: {r.data.tags}")
| print(f"status: {r.info.status}")
|
|
| # Create MLflow entities and a run under the default experiment (whose id is '0').
| timestamp = int(time.time() * 1000)
| metrics = [Metric("m", 1.5, timestamp, 1)]
| params = [Param("p", "p")]
| tags = [RunTag("t", "t")]
| experiment_id = "0"
| client = MlflowClient()
| run = client.create_run(experiment_id)
|
| # Log entities, terminate the run, and fetch run status
| client.log_batch(run.info.run_id, metrics=metrics, params=params, tags=tags)
| client.set_terminated(run.info.run_id)
| run = client.get_run(run.info.run_id)
| print_run_info(run)
|
| # To log metric in async fashion
| client.log_metric(run.info.run_id, "m", 1.5, synchronous=False)
|
| .. code-block:: text
| :caption: Output
|
| run_id: ef0247fa3205410595acc0f30f620871
| params: {'p': 'p'}
| metrics: {'m': 1.5}
| tags: {'t': 't'}
| status: FINISHED
|
| log_dict(self, run_id: str, dictionary: dict[str, typing.Any], artifact_file: str) -> None
| Log a JSON/YAML-serializable object (e.g. `dict`) as an artifact. The serialization
| format (JSON or YAML) is automatically inferred from the extension of `artifact_file`.
| If the file extension doesn't exist or match any of [".json", ".yml", ".yaml"],
| JSON format is used, and we stringify objects that can't be JSON-serialized.
|
| Args:
| run_id: String ID of the run.
| dictionary: Dictionary to log.
| artifact_file: The run-relative artifact file path in posixpath format to which
| the dictionary is saved (e.g. "dir/data.json").
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| run = client.create_run(experiment_id="0")
| run_id = run.info.run_id
|
| dictionary = {"k": "v"}
|
| # Log a dictionary as a JSON file under the run's root artifact directory
| client.log_dict(run_id, dictionary, "data.json")
|
| # Log a dictionary as a YAML file in a subdirectory of the run's root artifact directory
| client.log_dict(run_id, dictionary, "dir/data.yml")
|
| # If the file extension doesn't exist or match any of [".json", ".yaml", ".yml"],
| # JSON format is used.
| mlflow.log_dict(run_id, dictionary, "data")
| mlflow.log_dict(run_id, dictionary, "data.txt")
|
| log_figure(self, run_id: str, figure: Union[ForwardRef('matplotlib.figure.Figure'), ForwardRef('plotly.graph_objects.Figure')], artifact_file: str, *, save_kwargs: dict[str, typing.Any] | None = None) -> None
| Log a figure as an artifact. The following figure objects are supported:
|
| - `matplotlib.figure.Figure`_
| - `plotly.graph_objects.Figure`_
|
| .. _matplotlib.figure.Figure:
| https://matplotlib.org/api/_as_gen/matplotlib.figure.Figure.html
|
| .. _plotly.graph_objects.Figure:
| https://plotly.com/python-api-reference/generated/plotly.graph_objects.Figure.html
|
| Args:
| run_id: String ID of the run.
| figure: Figure to log.
| artifact_file: The run-relative artifact file path in posixpath format to which
| the figure is saved (e.g. "dir/file.png").
| save_kwargs: Additional keyword arguments passed to the method that saves the figure.
|
| .. code-block:: python
| :caption: Matplotlib Example
|
| import mlflow
| import matplotlib.pyplot as plt
|
| fig, ax = plt.subplots()
| ax.plot([0, 1], [2, 3])
|
| run = client.create_run(experiment_id="0")
| client.log_figure(run.info.run_id, fig, "figure.png")
|
| .. code-block:: python
| :caption: Plotly Example
|
| import mlflow
| from plotly import graph_objects as go
|
| fig = go.Figure(go.Scatter(x=[0, 1], y=[2, 3]))
|
| run = client.create_run(experiment_id="0")
| client.log_figure(run.info.run_id, fig, "figure.html")
|
| log_image(self, run_id: str, image: Union[ForwardRef('numpy.ndarray'), ForwardRef('PIL.Image.Image'), ForwardRef('mlflow.Image')], artifact_file: str | None = None, key: str | None = None, step: int | None = None, timestamp: int | None = None, synchronous: bool | None = None) -> None
| Logs an image in MLflow, supporting two use cases:
|
| 1. Time-stepped image logging:
| Ideal for tracking changes or progressions through iterative processes (e.g.,
| during model training phases).
|
| - Usage: :code:`log_image(image, key=key, step=step, timestamp=timestamp)`
|
| 2. Artifact file image logging:
| Best suited for static image logging where the image is saved directly as a file
| artifact.
|
| - Usage: :code:`log_image(image, artifact_file)`
|
| The following image formats are supported:
| - `numpy.ndarray`_
| - `PIL.Image.Image`_
|
| .. _numpy.ndarray:
| https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html
|
| .. _PIL.Image.Image:
| https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image
|
| - :class:`mlflow.Image`: An MLflow wrapper around PIL image for convenient image
| logging.
|
| Numpy array support
| - data types:
|
| - bool (useful for logging image masks)
| - integer [0, 255]
| - unsigned integer [0, 255]
| - float [0.0, 1.0]
|
| .. warning::
|
| - Out-of-range integer values will raise ValueError.
| - Out-of-range float values will auto-scale with min/max and warn.
|
| - shape (H: height, W: width):
|
| - H x W (Grayscale)
| - H x W x 1 (Grayscale)
| - H x W x 3 (an RGB channel order is assumed)
| - H x W x 4 (an RGBA channel order is assumed)
|
| Args:
| run_id: String ID of run.
| image: The image object to be logged.
| artifact_file: Specifies the path, in POSIX format, where the image
| will be stored as an artifact relative to the run's root directory (for
| example, "dir/image.png"). This parameter is kept for backward compatibility
| and should not be used together with `key`, `step`, or `timestamp`.
| key: Image name for time-stepped image logging. This string may only contain
| alphanumerics, underscores (_), dashes (-), periods (.), spaces ( ), and
| slashes (/).
| step: Integer training step (iteration) at which the image was saved.
| Defaults to 0.
| timestamp: Time when this image was saved. Defaults to the current system time.
| synchronous: *Experimental* If True, blocks until the metric is logged successfully.
| If False, logs the metric asynchronously and returns a future representing the
| logging operation. If None, read from environment variable
| `MLFLOW_ENABLE_ASYNC_LOGGING`, which defaults to False if not set.
|
| .. code-block:: python
| :caption: Time-stepped image logging numpy example
|
| import mlflow
| import numpy as np
|
| image = np.random.randint(0, 256, size=(100, 100, 3), dtype=np.uint8)
| with mlflow.start_run() as run:
| client = mlflow.MlflowClient()
| client.log_image(run.info.run_id, image, key="dogs", step=3)
|
| .. code-block:: python
| :caption: Time-stepped image logging pillow example
|
| import mlflow
| from PIL import Image
|
| image = Image.new("RGB", (100, 100))
| with mlflow.start_run() as run:
| client = mlflow.MlflowClient()
| client.log_image(run.info.run_id, image, key="dogs", step=3)
|
| .. code-block:: python
| :caption: Time-stepped image logging with mlflow.Image example
|
| import mlflow
| from PIL import Image
|
| # Saving an image to retrieve later.
| Image.new("RGB", (100, 100)).save("image.png")
|
| image = mlflow.Image("image.png")
| with mlflow.start_run() as run:
| client = mlflow.MlflowClient()
| client.log_image(run.info.run_id, image, key="dogs", step=3)
|
| .. code-block:: python
| :caption: Legacy artifact file image logging numpy example
|
| import mlflow
| import numpy as np
|
| image = np.random.randint(0, 256, size=(100, 100, 3), dtype=np.uint8)
| with mlflow.start_run() as run:
| client = mlflow.MlflowClient()
| client.log_image(run.info.run_id, image, "image.png")
|
| .. code-block:: python
| :caption: Legacy artifact file image logging pillow example
|
| import mlflow
| from PIL import Image
|
| image = Image.new("RGB", (100, 100))
| with mlflow.start_run() as run:
| client = mlflow.MlflowClient()
| client.log_image(run.info.run_id, image, "image.png")
|
| log_inputs(self, run_id: str, datasets: Optional[Sequence[mlflow.entities.dataset_input.DatasetInput]] = None, models: Optional[Sequence[mlflow.entities.logged_model_input.LoggedModelInput]] = None) -> None
| Log one or more dataset inputs to a run.
|
| Args:
| run_id: String ID of the run.
| datasets: List of :py:class:`mlflow.entities.DatasetInput` instances to log.
| models: List of :py:class:`mlflow.entities.LoggedModelInput` instances to log.
|
| Raises:
| mlflow.MlflowException: If any errors occur.
|
| log_metric(self, run_id: str, key: str, value: float, timestamp: int | None = None, step: int | None = None, synchronous: bool | None = None, dataset_name: str | None = None, dataset_digest: str | None = None, model_id: str | None = None) -> mlflow.utils.async_logging.run_operations.RunOperations | None
| Log a metric against the run ID.
|
| Args:
| run_id: The run id to which the metric should be logged.
| key: Metric name. This string may only contain alphanumerics, underscores
| (_), dashes (-), periods (.), spaces ( ), and slashes (/).
| All backend stores will support keys up to length 250, but some may
| support larger keys.
| value: Metric value. Note that some special values such
| as +/- Infinity may be replaced by other values depending on the store. For
| example, the SQLAlchemy store replaces +/- Inf with max / min float values.
| All backend stores will support values up to length 5000, but some
| may support larger values.
| timestamp: Time when this metric was calculated. Defaults to the current system time.
| step: Integer training step (iteration) at which was the metric calculated.
| Defaults to 0.
| synchronous: *Experimental* If True, blocks until the metric is logged successfully.
| If False, logs the metric asynchronously and returns a future representing the
| logging operation. If None, read from environment variable
| `MLFLOW_ENABLE_ASYNC_LOGGING`, which defaults to False if not set.
| dataset_name: The name of the dataset associated with the metric. If specified,
| ``dataset_digest`` must also be provided.
| dataset_digest: The digest of the dataset associated with the metric. If specified,
| ``dataset_name`` must also be provided.
| model_id: The ID of the model associated with the metric. If not specified, use the
| current active model ID set by :py:func:`mlflow.set_active_model`.
|
| Returns:
| When `synchronous=True` or None, returns None. When `synchronous=False`, returns an
| :py:class:`mlflow.utils.async_logging.run_operations.RunOperations` instance that
| represents future for logging operation.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_run_info(r):
| print(f"run_id: {r.info.run_id}")
| print(f"metrics: {r.data.metrics}")
| print(f"status: {r.info.status}")
|
|
| # Create a run under the default experiment (whose id is '0').
| # Since these are low-level CRUD operations, this method will create a run.
| # To end the run, you'll have to explicitly end it.
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| print_run_info(run)
| print("--")
|
| # Log the metric. Unlike mlflow.log_metric this method
| # does not start a run if one does not exist. It will log
| # the metric for the run id in the backend store.
| client.log_metric(run.info.run_id, "m", 1.5)
| client.set_terminated(run.info.run_id)
| run = client.get_run(run.info.run_id)
| print_run_info(run)
|
| # To log metric in async fashion
| client.log_metric(run.info.run_id, "m", 1.5, synchronous=False)
|
| .. code-block:: text
| :caption: Output
|
| run_id: 95e79843cb2c463187043d9065185e24
| metrics: {}
| status: RUNNING
| --
| run_id: 95e79843cb2c463187043d9065185e24
| metrics: {'m': 1.5}
| status: FINISHED
|
| log_model_artifact(self, model_id: str, local_path: str) -> None
| Upload an artifact to the specified logged model.
|
| Args:
| model_id: ID of the model.
| local_path: Local path to the artifact to upload.
|
| Returns:
| None
|
| log_model_artifacts(self, model_id: str, local_dir: str) -> None
| Upload a set of artifacts to the specified logged model.
|
| Args:
| model_id: ID of the model.
| local_dir: Local directory containing the artifacts to upload.
|
| Returns:
| None
|
| log_model_params(self, model_id: str, params: dict[str, str]) -> None
| Log parameters for a logged model.
|
| Args:
| model_id: ID of the model to log parameters for.
| params: Dictionary of parameters to log.
|
| Returns:
| None
|
| log_outputs(self, run_id: str, models: list[mlflow.entities.logged_model_output.LoggedModelOutput])
|
| log_param(self, run_id: str, key: str, value: Any, synchronous: bool | None = None) -> Any
| Log a parameter (e.g. model hyperparameter) against the run ID.
|
| Args:
| run_id: The run id to which the param should be logged.
| key: Parameter name. This string may only contain alphanumerics, underscores
| (_), dashes (-), periods (.), spaces ( ), and slashes (/).
| All backend stores support keys up to length 250, but some may
| support larger keys.
| value: Parameter value, but will be string-ified if not.
| All built-in backend stores support values up to length 6000, but some
| may support larger values.
| synchronous: *Experimental* If True, blocks until the metric is logged successfully.
| If False, logs the metric asynchronously and returns a future representing the
| logging operation. If None, read from environment variable
| `MLFLOW_ENABLE_ASYNC_LOGGING`, which defaults to False if not set.
|
| Returns:
| When `synchronous=True` or None, returns parameter value. When `synchronous=False`,
| returns an :py:class:`mlflow.utils.async_logging.run_operations.RunOperations`
| instance that represents future for logging operation.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_run_info(r):
| print(f"run_id: {r.info.run_id}")
| print(f"params: {r.data.params}")
| print(f"status: {r.info.status}")
|
|
| # Create a run under the default experiment (whose id is '0').
| # Since these are low-level CRUD operations, this method will create a run.
| # To end the run, you'll have to explicitly end it.
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| print_run_info(run)
| print("--")
| # Log the parameter. Unlike mlflow.log_param this method
| # does not start a run if one does not exist. It will log
| # the parameter in the backend store
| p_value = client.log_param(run.info.run_id, "p", 1)
| assert p_value == 1
| client.set_terminated(run.info.run_id)
| run = client.get_run(run.info.run_id)
| print_run_info(run)
|
| .. code-block:: text
| :caption: Output
|
| run_id: e649e49c7b504be48ee3ae33c0e76c93
| params: {}
| status: RUNNING
| --
| run_id: e649e49c7b504be48ee3ae33c0e76c93
| params: {'p': '1'}
| status: FINISHED
|
| log_stream(self, run_id: str, stream: io.BufferedIOBase | io.RawIOBase, artifact_file: str) -> None
| .. Note:: Experimental: This function may change or be removed in a future release without warning.
|
|
| Log a binary file-like object (e.g., ``io.BytesIO``) as an artifact.
|
| Args:
| run_id: String ID of the run.
| stream: A binary file-like object supporting ``.read()`` method
| (e.g., ``io.BytesIO``).
| artifact_file: The run-relative artifact file path in posixpath format to which
| the stream content is saved (e.g. "dir/file.bin").
|
| .. code-block:: python
| :caption: Example
|
| import io
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| run = client.create_run(experiment_id="0")
|
| # Log a BytesIO stream
| bytes_stream = io.BytesIO(b"binary content")
| client.log_stream(run.info.run_id, bytes_stream, "binary_file.bin")
|
| log_table(self, run_id: str, data: Union[dict[str, Any], ForwardRef('pandas.DataFrame')], artifact_file: str) -> None
| Log a table to MLflow Tracking as a JSON artifact. If the artifact_file already exists
| in the run, the data would be appended to the existing artifact_file.
|
| Args:
| run_id: String ID of the run.
| data: Dictionary or pandas.DataFrame to log.
| artifact_file: The run-relative artifact file path in posixpath format to which
| the table is saved (e.g. "dir/file.json").
|
| .. code-block:: python
| :test:
| :caption: Dictionary Example
|
| import mlflow
| from mlflow import MlflowClient
|
| table_dict = {
| "inputs": ["What is MLflow?", "What is Databricks?"],
| "outputs": ["MLflow is ...", "Databricks is ..."],
| "toxicity": [0.0, 0.0],
| }
| with mlflow.start_run() as run:
| client = MlflowClient()
| client.log_table(
| run.info.run_id, data=table_dict, artifact_file="qabot_eval_results.json"
| )
|
| .. code-block:: python
| :test:
| :caption: Pandas DF Example
|
| import mlflow
| import pandas as pd
| from mlflow import MlflowClient
|
| table_dict = {
| "inputs": ["What is MLflow?", "What is Databricks?"],
| "outputs": ["MLflow is ...", "Databricks is ..."],
| "toxicity": [0.0, 0.0],
| }
| df = pd.DataFrame.from_dict(table_dict)
| with mlflow.start_run() as run:
| client = MlflowClient()
| client.log_table(run.info.run_id, data=df, artifact_file="qabot_eval_results.json")
|
| .. code-block:: python
| :test:
| :caption: Image Column Example
|
| import mlflow
| import pandas as pd
| from mlflow import MlflowClient
|
| image = mlflow.Image([[1, 2, 3]])
| table_dict = {
| "inputs": ["Show me a dog", "Show me a cat"],
| "outputs": [image, image],
| }
| df = pd.DataFrame.from_dict(table_dict)
| with mlflow.start_run() as run:
| client = MlflowClient()
| client.log_table(run.info.run_id, data=df, artifact_file="image_gen.json")
|
| log_text(self, run_id: str, text: str, artifact_file: str) -> None
| Log text as an artifact.
|
| Args:
| run_id: String ID of the run.
| text: String containing text to log.
| artifact_file: The run-relative artifact file path in posixpath format to which
| the text is saved (e.g. "dir/file.txt").
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| run = client.create_run(experiment_id="0")
|
| # Log text to a file under the run's root artifact directory
| client.log_text(run.info.run_id, "text1", "file1.txt")
|
| # Log text in a subdirectory of the run's root artifact directory
| client.log_text(run.info.run_id, "text2", "dir/file2.txt")
|
| # Log HTML text
| client.log_text(run.info.run_id, "<h1>header</h1>", "index.html")
|
| parse_prompt_uri(self, uri: str) -> tuple[str, str]
| Parse prompt URI into prompt name and prompt version.
| - 'prompts:/<name>/<version>' -> ('<name>', '<version>')
| - 'prompts:/<name>@<alias>' -> ('<name>', '<version>')
|
| This method reuses the existing model URI parsing logic with prompts prefix.
|
| refresh_mcp_server_version_tools(self, name: str, version: str, mcp_server_access_headers: Optional[Mapping[str, str]] = None, dry_run: bool = False) -> mlflow.entities.mcp_server_version.MCPServerVersion
|
| register_prompt(self, name: str, template: str | list[dict[str, typing.Any]], commit_message: str | None = None, tags: dict[str, str] | None = None, response_format: type[pydantic.main.BaseModel] | dict[str, typing.Any] | None = None, model_config: 'PromptModelConfig | dict[str, Any] | None' = None) -> mlflow.entities.model_registry.prompt_version.PromptVersion
| Register a new :py:class:`Prompt <mlflow.entities.Prompt>` in the MLflow Prompt Registry.
|
| A :py:class:`Prompt <mlflow.entities.Prompt>` is a pair of name
| and template content at minimum. With MLflow Prompt Registry, you can create, manage,
| and version control prompts with the MLflow's robust model tracking framework.
|
| If there is no registered prompt with the given name, a new prompt will be created.
| Otherwise, a new version of the existing prompt will be created.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
| from pydantic import BaseModel
|
| # Your prompt registry URI
| client = MlflowClient(registry_uri="sqlite:///prompt_registry.db")
|
| # Register a text prompt
| client.register_prompt(
| name="greeting_prompt",
| template="Respond to the user's message as a {{style}} AI.",
| response_format={"type": "string", "description": "A friendly response"},
| )
|
| # Register a chat prompt with multiple messages
| client.register_prompt(
| name="assistant_prompt",
| template=[
| {"role": "system", "content": "You are a helpful {{style}} assistant."},
| {"role": "user", "content": "{{question}}"},
| ],
| response_format={"type": "object", "properties": {"answer": {"type": "string"}}},
| )
|
| # Load the prompt from the registry
| prompt = client.load_prompt("greeting_prompt")
|
| # Use the prompt in your application
| import openai
|
| openai_client = openai.OpenAI()
| openai_client.chat.completion.create(
| model="gpt-4o-mini",
| messages=[
| {"role": "system", "content": prompt.format(style="friendly")},
| {"role": "user", "content": "Hello, how are you?"},
| ],
| )
|
| # Update the prompt with a new version
| prompt = client.register_prompt(
| name="greeting_prompt",
| template="Respond to the user's message as a {{style}} AI. {{greeting}}",
| commit_message="Add a greeting to the prompt.",
| tags={"author": "Bob"},
| )
|
| Args:
| name: The name of the prompt.
| template: The template content of the prompt. Can be either:
|
| - A string containing text with variables enclosed in double curly braces,
| e.g. {{variable}}, which will be replaced with actual values by the `format`
| method.
| - A list of dictionaries representing chat messages, where each message has
| 'role' and 'content' keys (e.g., [{"role": "user", "content": "Hello {{name}}"}])
|
| commit_message: A message describing the changes made to the prompt, similar to a
| Git commit message. Optional.
| tags: A dictionary of tags for the prompt.
| These tags are stored on the prompt version and written to prompt-level metadata.
| For OSS, later ``register_prompt()`` calls can overwrite the same keys at the
| prompt level. Optional.
| response_format: Optional Pydantic class or dictionary defining the expected response
| structure. This can be used to specify the schema for structured outputs from LLM
| calls.
| model_config: Optional PromptModelConfig instance or dictionary containing
| model-specific configuration like model_name, temperature, max_tokens, etc.
| Using PromptModelConfig provides validation and type safety.
|
| Returns:
| A :py:class:`Prompt <mlflow.entities.Prompt>` object that was created.
|
| remove_dataset_from_experiments(self, dataset_id: str, experiment_ids: list[str]) -> mlflow.entities.evaluation_dataset.EvaluationDataset
| Remove a dataset from experiments.
|
| This operation is idempotent - removing non-existent associations will not raise errors.
|
| Args:
| dataset_id: The ID of the dataset to update.
| experiment_ids: List of experiment IDs to remove association from.
|
| Returns:
| The updated EvaluationDataset with removed experiment associations.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Remove dataset from experiments
| dataset = client.remove_dataset_from_experiments(
| dataset_id="d-abc123", experiment_ids=["2", "3"]
| )
| print(f"Dataset now associated with {len(dataset.experiment_ids)} experiments")
|
| rename_experiment(self, experiment_id: str, new_name: str) -> None
| Update an experiment's name. The new name must be unique.
|
| Args:
| experiment_id: The experiment ID returned from ``create_experiment``.
| new_name: The new name for the experiment.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_experiment_info(experiment):
| print(f"Name: {experiment.name}")
| print(f"Experiment_id: {experiment.experiment_id}")
| print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
|
|
| # Create an experiment with a name that is unique and case sensitive
| client = MlflowClient()
| experiment_id = client.create_experiment("Social NLP Experiments")
|
| # Fetch experiment metadata information
| experiment = client.get_experiment(experiment_id)
| print_experiment_info(experiment)
| print("--")
|
| # Rename and fetch experiment metadata information
| client.rename_experiment(experiment_id, "Social Media NLP Experiments")
| experiment = client.get_experiment(experiment_id)
| print_experiment_info(experiment)
|
| .. code-block:: text
| :caption: Output
|
| Name: Social NLP Experiments
| Experiment_id: 1
| Lifecycle_stage: active
| --
| Name: Social Media NLP Experiments
| Experiment_id: 1
| Lifecycle_stage: active
|
| rename_registered_model(self, name: str, new_name: str) -> mlflow.entities.model_registry.registered_model.RegisteredModel
| Update registered model name.
|
| Args:
| name: Name of the registered model to update.
| new_name: New proposed name for the registered model.
|
| Returns:
| A single updated :py:class:`mlflow.entities.model_registry.RegisteredModel` object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
|
| def print_registered_model_info(rm):
| print(f"name: {rm.name}")
| print(f"tags: {rm.tags}")
| print(f"description: {rm.description}")
|
|
| name = "SocialTextAnalyzer"
| tags = {"nlp.framework": "Spark NLP"}
| desc = "This sentiment analysis model classifies the tone-happy, sad, angry."
|
| # create a new registered model name
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| client = MlflowClient()
| client.create_registered_model(name, tags, desc)
| print_registered_model_info(client.get_registered_model(name))
| print("--")
|
| # rename the model
| new_name = "SocialMediaTextAnalyzer"
| client.rename_registered_model(name, new_name)
| print_registered_model_info(client.get_registered_model(new_name))
|
| .. code-block:: text
| :caption: Output
|
| name: SocialTextAnalyzer
| tags: {'nlp.framework': 'Spark NLP'}
| description: This sentiment analysis model classifies the tone-happy, sad, angry.
| --
| name: SocialMediaTextAnalyzer
| tags: {'nlp.framework': 'Spark NLP'}
| description: This sentiment analysis model classifies the tone-happy, sad, angry.
|
| restore_experiment(self, experiment_id: str) -> None
| Restore a deleted experiment unless permanently deleted.
|
| Args:
| experiment_id: The experiment ID returned from ``create_experiment``.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_experiment_info(experiment):
| print(f"Name: {experiment.name}")
| print(f"Experiment Id: {experiment.experiment_id}")
| print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
|
|
| # Create and delete an experiment
| client = MlflowClient()
| experiment_id = client.create_experiment("New Experiment")
| client.delete_experiment(experiment_id)
|
| # Examine the deleted experiment details.
| experiment = client.get_experiment(experiment_id)
| print_experiment_info(experiment)
| print("--")
|
| # Restore the experiment and fetch its info
| client.restore_experiment(experiment_id)
| experiment = client.get_experiment(experiment_id)
| print_experiment_info(experiment)
|
| .. code-block:: text
| :caption: Output
|
| Name: New Experiment
| Experiment Id: 1
| Lifecycle_stage: deleted
| --
| Name: New Experiment
| Experiment Id: 1
| Lifecycle_stage: active
|
| restore_run(self, run_id: str) -> None
| Restores a deleted run with the given ID.
|
| Args:
| run_id: The unique run id to restore.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| # Create a run under the default experiment (whose id is '0').
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| run_id = run.info.run_id
| print(f"run_id: {run_id}; lifecycle_stage: {run.info.lifecycle_stage}")
| client.delete_run(run_id)
| del_run = client.get_run(run_id)
| print(f"run_id: {run_id}; lifecycle_stage: {del_run.info.lifecycle_stage}")
| client.restore_run(run_id)
| rest_run = client.get_run(run_id)
| print(f"run_id: {run_id}; lifecycle_stage: {rest_run.info.lifecycle_stage}")
|
| .. code-block:: text
| :caption: Output
|
| run_id: 7bc59754d7e74534a7917d62f2873ac0; lifecycle_stage: active
| run_id: 7bc59754d7e74534a7917d62f2873ac0; lifecycle_stage: deleted
| run_id: 7bc59754d7e74534a7917d62f2873ac0; lifecycle_stage: active
|
| search_datasets(self, experiment_ids: list[str] | None = None, filter_string: str | None = None, max_results: int = 50, order_by: list[str] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.evaluation_dataset.EvaluationDataset]
| Search for datasets.
|
| Args:
| experiment_ids: List of experiment IDs to filter by.
| filter_string: A filter string to apply to the search.
| max_results: Maximum number of results to return. Defaults to 50.
| order_by: List of columns to order by.
| page_token: Token for the next page of results.
|
| Returns:
| A PagedList of EvaluationDataset objects.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Search for datasets in specific experiments
| datasets = client.search_datasets(
| experiment_ids=["exp1", "exp2"], filter_string="name LIKE 'qa_%'", max_results=10
| )
|
| # Get next page if available
| if datasets.token:
| next_page = client.search_datasets(
| experiment_ids=["exp1", "exp2"], page_token=datasets.token
| )
|
| search_experiments(self, view_type: int = 1, max_results: int | None = 1000, filter_string: str | None = None, order_by: list[str] | None = None, page_token=None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.experiment.Experiment]
| Search for experiments that match the specified search query.
|
| Args:
| view_type: One of enum values ``ACTIVE_ONLY``, ``DELETED_ONLY``, or ``ALL``
| defined in :py:class:`mlflow.entities.ViewType`.
| max_results: Maximum number of experiments desired. Certain server backend may apply
| its own limit.
| filter_string: Filter query string (e.g., ``"name = 'my_experiment'"``), defaults to
| searching for all experiments. The following identifiers, comparators, and logical
| operators are supported.
|
| Identifiers
| - ``name``: Experiment name
| - ``creation_time``: Experiment creation time
| - ``last_update_time``: Experiment last update time
| - ``tags.<tag_key>``: Experiment tag. If ``tag_key`` contains
| spaces, it must be wrapped with backticks (e.g., ``"tags.`extra key`"``).
|
| Comparators for string attributes and tags
| - ``=``: Equal to
| - ``!=``: Not equal to
| - ``LIKE``: Case-sensitive pattern match
| - ``ILIKE``: Case-insensitive pattern match
|
| Comparators for numeric attributes
| - ``=``: Equal to
| - ``!=``: Not equal to
| - ``<``: Less than
| - ``<=``: Less than or equal to
| - ``>``: Greater than
| - ``>=``: Greater than or equal to
|
| Logical operators
| - ``AND``: Combines two sub-queries and returns True if both of them are True.
|
| order_by: List of columns to order by. The ``order_by`` column can contain an optional
| ``DESC`` or ``ASC`` value (e.g., ``"name DESC"``). The default ordering is ``ASC``,
| so ``"name"`` is equivalent to ``"name ASC"``. If unspecified, defaults to
| ``["last_update_time DESC"]``, which lists experiments updated most recently first.
| The following fields are supported:
|
| - ``experiment_id``: Experiment ID
| - ``name``: Experiment name
| - ``creation_time``: Experiment creation time
| - ``last_update_time``: Experiment last update time
|
| page_token: Token specifying the next page of results. It should be obtained from
| a ``search_experiments`` call.
|
| Returns:
| A :py:class:`PagedList <mlflow.store.entities.PagedList>` of
| :py:class:`Experiment <mlflow.entities.Experiment>` objects. The pagination token
| for the next page can be obtained via the ``token`` attribute of the object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
|
|
| def assert_experiment_names_equal(experiments, expected_names):
| actual_names = [e.name for e in experiments if e.name != "Default"]
| assert actual_names == expected_names, (actual_names, expected_names)
|
|
| mlflow.set_tracking_uri("sqlite:///:memory:")
| client = mlflow.MlflowClient()
|
| # Create experiments
| for name, tags in [
| ("a", None),
| ("b", None),
| ("ab", {"k": "v"}),
| ("bb", {"k": "V"}),
| ]:
| client.create_experiment(name, tags=tags)
|
| # Search for experiments with name "a"
| experiments = client.search_experiments(filter_string="name = 'a'")
| assert_experiment_names_equal(experiments, ["a"])
|
| # Search for experiments with name starting with "a"
| experiments = client.search_experiments(filter_string="name LIKE 'a%'")
| assert_experiment_names_equal(experiments, ["ab", "a"])
|
| # Search for experiments with tag key "k" and value ending with "v" or "V"
| experiments = client.search_experiments(filter_string="tags.k ILIKE '%v'")
| assert_experiment_names_equal(experiments, ["bb", "ab"])
|
| # Search for experiments with name ending with "b" and tag {"k": "v"}
| experiments = client.search_experiments(filter_string="name LIKE '%b' AND tags.k = 'v'")
| assert_experiment_names_equal(experiments, ["ab"])
|
| # Sort experiments by name in ascending order
| experiments = client.search_experiments(order_by=["name"])
| assert_experiment_names_equal(experiments, ["a", "ab", "b", "bb"])
|
| # Sort experiments by ID in descending order
| experiments = client.search_experiments(order_by=["experiment_id DESC"])
| assert_experiment_names_equal(experiments, ["bb", "ab", "b", "a"])
|
| search_logged_models(self, experiment_ids: list[str], filter_string: str | None = None, datasets: list[dict[str, typing.Any]] | None = None, max_results: int | None = None, order_by: list[dict[str, typing.Any]] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.logged_model.LoggedModel]
| Search for logged models that match the specified search criteria.
|
| Args:
| experiment_ids: List of experiment ids to scope the search.
| filter_string: A SQL-like filter string to parse. The filter string syntax supports:
|
| - Entity specification:
| - attributes: `attribute_name` (default if no prefix is specified)
| - metrics: `metrics.metric_name`
| - parameters: `params.param_name`
| - tags: `tags.tag_name`
| - Comparison operators:
| - For numeric entities (metrics and numeric attributes): <, <=, >, >=, =, !=
| - For string entities (params, tags, string attributes): =, !=, IN, NOT IN
| - Multiple conditions can be joined with 'AND'
| - String values must be enclosed in single quotes
|
| Example filter strings:
| - `creation_time > 100`
| - `metrics.rmse > 0.5 AND params.model_type = 'rf'`
| - `tags.release IN ('v1.0', 'v1.1')`
| - `params.optimizer != 'adam' AND metrics.accuracy >= 0.9`
| datasets: List of dictionaries to specify datasets on which to apply metrics filters
| For example, a filter string with `metrics.accuracy > 0.9` and dataset with name
| "test_dataset" means we will return all logged models with accuracy > 0.9 on the
| test_dataset. Metric values from ANY dataset matching the criteria are considered.
| If no datasets are specified, then metrics across all datasets are considered in
| the filter. The following fields are supported:
|
| dataset_name (str):
| Required. Name of the dataset.
| dataset_digest (str):
| Optional. Digest of the dataset.
| max_results: Maximum number of logged models desired.
| order_by: List of dictionaries to specify the ordering of the search results.
| The following fields are supported:
|
| field_name (str):
| Required. Name of the field to order by, e.g. "metrics.accuracy".
| ascending (bool):
| Optional. Whether the order is ascending or not.
| dataset_name (str):
| Optional. If ``field_name`` refers to a metric, this field
| specifies the name of the dataset associated with the metric. Only metrics
| associated with the specified dataset name will be considered for ordering.
| This field may only be set if ``field_name`` refers to a metric.
| dataset_digest (str):
| Optional. If ``field_name`` refers to a metric, this field
| specifies the digest of the dataset associated with the metric. Only metrics
| associated with the specified dataset name and digest will be considered for
| ordering. This field may only be set if ``dataset_name`` is also set.
| page_token: Token specifying the next page of results.
|
| Returns:
| A :py:class:`PagedList <mlflow.store.entities.PagedList>` of
| :py:class:`LoggedModel <mlflow.entities.LoggedModel>` objects.
|
| search_mcp_access_endpoints(self, server_name: str | None = None, server_version: str | None = None, server_alias: str | None = None, filter_string: str | None = None, max_results: int = 1000, order_by: list[str] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.mcp_access_endpoint.MCPAccessEndpoint]
|
| search_mcp_server_versions(self, name: str, filter_string: str | None = None, max_results: int = 1000, order_by: list[str] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.mcp_server_version.MCPServerVersion]
|
| search_mcp_servers(self, filter_string: str | None = None, max_results: int = 1000, order_by: list[str] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.mcp_server.MCPServer]
|
| search_model_versions(self, filter_string: str | None = None, max_results: int = 10000, order_by: list[str] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.model_registry.model_version.ModelVersion]
| Search for model versions in backend that satisfy the filter criteria.
|
| .. warning:
| The model version search results may not have aliases populated for performance reasons.
|
| Args:
| filter_string: Filter query string
| (e.g., ``"name = 'a_model_name' and tag.key = 'value1'"``),
| defaults to searching for all model versions. The following identifiers,
| comparators, and logical operators are supported.
|
| Identifiers
| - ``name``: model name.
| - ``source_path``: model version source path.
| - ``run_id``: The id of the mlflow run that generates the model version.
| - ``tags.<tag_key>``: model version tag. If ``tag_key`` contains spaces, it must
| be wrapped with backticks (e.g., ``"tags.`extra key`"``).
|
| Comparators
| - ``=``: Equal to.
| - ``!=``: Not equal to.
| - ``LIKE``: Case-sensitive pattern match.
| - ``ILIKE``: Case-insensitive pattern match.
| - ``IN``: In a value list. Only ``run_id`` identifier supports ``IN`` comparator.
|
| Logical operators
| - ``AND``: Combines two sub-queries and returns True if both of them are True.
|
| max_results: Maximum number of model versions desired.
| order_by: List of column names with ASC|DESC annotation, to be used for ordering
| matching search results.
| page_token: Token specifying the next page of results. It should be obtained from
| a ``search_model_versions`` call.
|
| Returns:
| A PagedList of :py:class:`mlflow.entities.model_registry.ModelVersion`
| objects that satisfy the search expressions. The pagination token for the next
| page can be obtained via the ``token`` attribute of the object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Get all versions of the model filtered by name
| model_name = "CordobaWeatherForecastModel"
| filter_string = f"name='{model_name}'"
| results = client.search_model_versions(filter_string)
| print("-" * 80)
| for res in results:
| print(f"name={res.name}; run_id={res.run_id}; version={res.version}")
|
| # Get the version of the model filtered by run_id
| run_id = "e14afa2f47a040728060c1699968fd43"
| filter_string = f"run_id='{run_id}'"
| results = client.search_model_versions(filter_string)
| print("-" * 80)
| for res in results:
| print(f"name={res.name}; run_id={res.run_id}; version={res.version}")
|
| .. code-block:: text
| :caption: Output
|
| ------------------------------------------------------------------------------------
| name=CordobaWeatherForecastModel; run_id=eaef868ee3d14d10b4299c4c81ba8814; version=1
| name=CordobaWeatherForecastModel; run_id=e14afa2f47a040728060c1699968fd43; version=2
| ------------------------------------------------------------------------------------
| name=CordobaWeatherForecastModel; run_id=e14afa2f47a040728060c1699968fd43; version=2
|
| search_prompt_versions(self, name: str, max_results: int | None = None, page_token: str | None = None)
| Search prompt versions for a given prompt name.
|
| Args:
| name: Name of the prompt to search versions for.
| max_results: Maximum number of versions to return.
| page_token: Token for pagination.
|
| Returns:
| A :py:class:`PagedList <mlflow.store.entities.PagedList>` of
| :py:class:`~mlflow.entities.model_registry.PromptVersion` objects.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| versions = client.search_prompt_versions("my_prompt", max_results=10)
| for version in versions:
| print(f"Version {version.version}: {version.template}")
|
| search_prompts(self, filter_string: str | None = None, max_results: int = 1000, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.model_registry.prompt.Prompt]
| Search for prompts in the MLflow Prompt Registry.
|
| This call returns prompt metadata for prompts that have been marked
| as prompts (i.e. tagged with `mlflow.prompt.is_prompt=true`). We can
| further restrict results via a standard registry filter expression.
|
| Args:
| filter_string (Optional[str]):
| An additional registry-search expression to apply (e.g.
| `"name LIKE 'my_prompt%'"`). For Unity Catalog registries, must include
| catalog and schema: "catalog = 'catalog_name' AND schema = 'schema_name'".
| max_results (int):
| The maximum number of prompts to return in one page. Defaults
| to `SEARCH_MAX_RESULTS_DEFAULT` (typically 1 000).
| page_token (Optional[str]):
| A pagination token from a previous `search_prompts` call; use this
| to retrieve the next page of results. Defaults to `None`.
|
| Returns:
| A pageable list of :py:class:`Prompt <mlflow.entities.Prompt>` objects
| representing prompt metadata:
|
| - name: The prompt name
| - description: The prompt description
| - tags: Prompt-level tags
| - creation_timestamp: When the prompt was created
|
| To get the actual prompt template content,
| use get_prompt_version() with a specific version:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| # Your prompt registry URI
| client = MlflowClient(registry_uri="sqlite:///prompt_registry.db")
|
| # Search for prompts
| prompts = client.search_prompts(filter_string="name LIKE 'greeting%'")
|
| # Get prompts by experiment
| prompts = client.search_prompts(filter_string='experiment_id = "1"')
|
| # Get specific version content
| for prompt in prompts:
| prompt_version = client.get_prompt_version(prompt.name, version="1")
| print(f"Template: {prompt_version.template}")
|
| Inspect the returned object's `.token` attribute to fetch subsequent pages.
|
| search_registered_models(self, filter_string: str | None = None, max_results: int = 100, order_by: list[str] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.model_registry.registered_model.RegisteredModel]
| Search for registered models in backend that satisfy the filter criteria.
|
| Args:
| filter_string: Filter query string (e.g., "name = 'a_model_name' and tag.key =
| 'value1'"), defaults to searching for all registered models. The following
| identifiers, comparators, and logical operators are supported.
|
| Identifiers
| - ``name``: registered model name.
| - ``tags.<tag_key>``: registered model tag. If ``tag_key`` contains spaces, it
| must be wrapped with backticks (e.g., "tags.`extra key`").
|
| Comparators
| - ``=``: Equal to.
| - ``!=``: Not equal to.
| - ``LIKE``: Case-sensitive pattern match.
| - ``ILIKE``: Case-insensitive pattern match.
|
| Logical operators
| - ``AND``: Combines two sub-queries and returns True if both of them are True.
|
| max_results: Maximum number of registered models desired.
| order_by: List of column names with ASC|DESC annotation, to be used for ordering
| matching search results.
| page_token: Token specifying the next page of results. It should be obtained from
| a ``search_registered_models`` call.
|
| Returns:
| A PagedList of :py:class:`mlflow.entities.model_registry.RegisteredModel` objects
| that satisfy the search expressions. The pagination token for the next page can be
| obtained via the ``token`` attribute of the object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Get search results filtered by the registered model name
| model_name = "CordobaWeatherForecastModel"
| filter_string = f"name='{model_name}'"
| results = client.search_registered_models(filter_string=filter_string)
| print("-" * 80)
| for res in results:
| for mv in res.latest_versions:
| print(f"name={mv.name}; run_id={mv.run_id}; version={mv.version}")
|
| # Get search results filtered by the registered model name that matches
| # prefix pattern
| filter_string = "name LIKE 'Boston%'"
| results = client.search_registered_models(filter_string=filter_string)
| print("-" * 80)
| for res in results:
| for mv in res.latest_versions:
| print(f"name={mv.name}; run_id={mv.run_id}; version={mv.version}")
|
| # Get all registered models and order them by ascending order of the names
| results = client.search_registered_models(order_by=["name ASC"])
| print("-" * 80)
| for res in results:
| for mv in res.latest_versions:
| print(f"name={mv.name}; run_id={mv.run_id}; version={mv.version}")
|
| .. code-block:: text
| :caption: Output
|
| ------------------------------------------------------------------------------------
| name=CordobaWeatherForecastModel; run_id=eaef868ee3d14d10b4299c4c81ba8814; version=1
| name=CordobaWeatherForecastModel; run_id=e14afa2f47a040728060c1699968fd43; version=2
| ------------------------------------------------------------------------------------
| name=BostonWeatherForecastModel; run_id=ddc51b9407a54b2bb795c8d680e63ff6; version=1
| name=BostonWeatherForecastModel; run_id=48ac94350fba40639a993e1b3d4c185d; version=2
| -----------------------------------------------------------------------------------
| name=AzureWeatherForecastModel; run_id=5fcec6c4f1c947fc9295fef3fa21e52d; version=1
| name=AzureWeatherForecastModel; run_id=8198cb997692417abcdeb62e99052260; version=3
| name=BostonWeatherForecastModel; run_id=ddc51b9407a54b2bb795c8d680e63ff6; version=1
| name=BostonWeatherForecastModel; run_id=48ac94350fba40639a993e1b3d4c185d; version=2
| name=CordobaWeatherForecastModel; run_id=eaef868ee3d14d10b4299c4c81ba8814; version=1
| name=CordobaWeatherForecastModel; run_id=e14afa2f47a040728060c1699968fd43; version=2
|
| search_runs(self, experiment_ids: list[str], filter_string: str = '', run_view_type: int = 1, max_results: int = 1000, order_by: list[str] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.run.Run]
| Search for Runs that fit the specified criteria.
|
| Args:
| experiment_ids: List of experiment IDs, or a single int or string id.
| filter_string: Filter query string, defaults to searching all runs.
| run_view_type: one of enum values ACTIVE_ONLY, DELETED_ONLY, or ALL runs
| defined in :py:class:`mlflow.entities.ViewType`.
| max_results: Maximum number of runs desired.
| order_by: List of columns to order by (e.g., "metrics.rmse"). The ``order_by`` column
| can contain an optional ``DESC`` or ``ASC`` value. The default is ``ASC``.
| The default ordering is to sort by ``start_time DESC``, then ``run_id``.
| page_token: Token specifying the next page of results. It should be obtained from
| a ``search_runs`` call.
|
| Returns:
| A :py:class:`PagedList <mlflow.store.entities.PagedList>` of
| :py:class:`Run <mlflow.entities.Run>` objects that satisfy the search expressions.
| If the underlying tracking store supports pagination, the token for the next page may
| be obtained via the ``token`` attribute of the returned object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
| from mlflow.entities import ViewType
|
|
| def print_run_info(runs):
| for r in runs:
| print(f"run_id: {r.info.run_id}")
| print(f"lifecycle_stage: {r.info.lifecycle_stage}")
| print(f"metrics: {r.data.metrics}")
| # Exclude mlflow system tags
| tags = {k: v for k, v in r.data.tags.items() if not k.startswith("mlflow.")}
| print(f"tags: {tags}")
|
|
| # Create an experiment and log two runs with metrics and tags under the experiment
| experiment_id = mlflow.create_experiment("Social NLP Experiments")
| with mlflow.start_run(experiment_id=experiment_id) as run:
| mlflow.log_metric("m", 1.55)
| mlflow.set_tag("s.release", "1.1.0-RC")
| with mlflow.start_run(experiment_id=experiment_id):
| mlflow.log_metric("m", 2.50)
| mlflow.set_tag("s.release", "1.2.0-GA")
| # Search all runs under experiment id and order them by
| # descending value of the metric 'm'
| client = MlflowClient()
| runs = client.search_runs(experiment_id, order_by=["metrics.m DESC"])
| print_run_info(runs)
| print("--")
| # Delete the first run
| client.delete_run(run_id=run.info.run_id)
| # Search only deleted runs under the experiment id and use a case insensitive pattern
| # in the filter_string for the tag.
| filter_string = "tags.s.release ILIKE '%rc%'"
| runs = client.search_runs(
| experiment_id, run_view_type=ViewType.DELETED_ONLY, filter_string=filter_string
| )
| print_run_info(runs)
|
| .. code-block:: text
| :caption: Output
|
| run_id: 0efb2a68833d4ee7860a964fad31cb3f
| lifecycle_stage: active
| metrics: {'m': 2.5}
| tags: {'s.release': '1.2.0-GA'}
| run_id: 7ab027fd72ee4527a5ec5eafebb923b8
| lifecycle_stage: active
| metrics: {'m': 1.55}
| tags: {'s.release': '1.1.0-RC'}
| --
| run_id: 7ab027fd72ee4527a5ec5eafebb923b8
| lifecycle_stage: deleted
| metrics: {'m': 1.55}
| tags: {'s.release': '1.1.0-RC'}
|
| search_traces(self, experiment_ids: list[str] | None = None, filter_string: str | None = None, max_results: int = 100, order_by: list[str] | None = None, page_token: str | None = None, run_id: str | None = None, include_spans: bool = True, model_id: str | None = None, locations: list[str] | None = None, flush: bool = False) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.trace.Trace]
| .. Note:: Parameter ``experiment_ids`` is deprecated. Use ``locations`` instead.
|
| Return traces that match the given list of search expressions within the experiments.
|
| Args:
| experiment_ids: List of experiment ids to scope the search.
| filter_string: A search filter string.
| max_results: Maximum number of traces desired.
| order_by: List of order_by clauses.
| page_token: Token specifying the next page of results. It should be obtained from
| a ``search_traces`` call.
| run_id: A run id to scope the search. When a trace is created under an active run,
| it will be associated with the run and you can filter on the run id to retrieve
| the trace.
| include_spans: If ``True``, include spans in the returned traces. Otherwise, only
| the trace metadata is returned, e.g., trace ID, start time, end time, etc,
| without any spans.
| model_id: If specified, return traces associated with the model ID.
| locations: A list of locations to search over. To search over experiments, provide
| a list of experiment IDs. To search over UC tables on databricks, provide
| a list of locations in the format `<catalog_name>.<schema_name>`.
| flush: If ``True``, flush any pending async trace writes before searching.
| Useful in tests or scripts to ensure all traces are visible. Default to ``False``.
|
| Returns:
| A :py:class:`PagedList <mlflow.store.entities.PagedList>` of
| :py:class:`Trace <mlflow.entities.Trace>` objects that satisfy the search
| expressions. If the underlying tracking store supports pagination, the token for the
| next page may be obtained via the ``token`` attribute of the returned object; however,
| some store implementations may not support pagination and thus the returned token would
| not be meaningful in such cases.
|
| set_dataset_tags(self, dataset_id: str, tags: dict[str, typing.Any]) -> None
| Set tags for a dataset.
|
| This implements an upsert operation - existing tags are merged with new tags.
| To remove a tag, set its value to None.
|
| Args:
| dataset_id: The ID of the dataset to update.
| tags: Dictionary of tags to update. Setting a value to None removes the tag.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Set tags for a dataset
| client.set_dataset_tags(
| dataset_id="dataset123",
| tags={
| "environment": "production",
| "version": "2.0",
| "deprecated": None, # This removes the 'deprecated' tag
| },
| )
|
| set_experiment_tag(self, experiment_id: str, key: str, value: Any) -> None
| Set a tag on the experiment with the specified ID. Value is converted to a string.
|
| Args:
| experiment_id: String ID of the experiment.
| key: Name of the tag.
| value: Tag value (converted to a string).
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| # Create an experiment and set its tag
| client = MlflowClient()
| experiment_id = client.create_experiment("Social Media NLP Experiments")
| client.set_experiment_tag(experiment_id, "nlp.framework", "Spark NLP")
|
| # Fetch experiment metadata information
| experiment = client.get_experiment(experiment_id)
| print(f"Name: {experiment.name}")
| print(f"Tags: {experiment.tags}")
|
| .. code-block:: text
|
| Name: Social Media NLP Experiments
| Tags: {'nlp.framework': 'Spark NLP'}
|
| set_logged_model_tags(self, model_id: str, tags: dict[str, typing.Any]) -> None
| Set tags on the specified logged model.
|
| Args:
| model_id: ID of the model.
| tags: Tags to set on the model.
|
| Returns:
| None
|
| set_mcp_server_alias(self, name: str, alias: str, version: str) -> None
|
| set_mcp_server_tag(self, name: str, key: str, value: str) -> None
|
| set_mcp_server_version_tag(self, name: str, version: str, key: str, value: str) -> None
|
| set_model_version_tag(self, name: str, version: str | None = None, key: str | None = None, value: Any = None, stage: str | None = None) -> None
| Set a tag for the model version.
| When stage is set, tag will be set for latest model version of the stage.
| Setting both version and stage parameter will result in error.
|
| Args:
| name: Registered model name.
| version: Registered model version.
| key: Tag key to log. key is required.
| value: Tag value to log. value is required.
| stage: Registered model stage.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_version_info(mv):
| print(f"Name: {mv.name}")
| print(f"Version: {mv.version}")
| print(f"Tags: {mv.tags}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a new version of the rfr model under the registered model name
| # and set a tag
| model_uri = f"runs:/{run.info.run_id}/sklearn-model"
| mv = client.create_model_version(name, model_uri, run.info.run_id)
| print_model_version_info(mv)
| print("--")
|
| # Tag using model version
| client.set_model_version_tag(name, mv.version, "t", "1")
|
| # Tag using model stage
| client.set_model_version_tag(name, key="t1", value="1", stage=mv.current_stage)
| mv = client.get_model_version(name, mv.version)
| print_model_version_info(mv)
|
| .. code-block:: text
| :caption: Output
|
| Name: RandomForestRegression
| Version: 1
| Tags: {}
| --
| Name: RandomForestRegression
| Version: 1
| Tags: {'t': '1', 't1': '1'}
|
| set_prompt_alias(self, name: str, alias: str, version: int) -> None
| Set an alias for a :py:class:`Prompt <mlflow.entities.Prompt>`.
|
| Args:
| name: The name of the prompt.
| alias: The alias to set for the prompt.
| version: The version of the prompt.
|
| set_prompt_tag(self, name: str, key: str, value: str) -> None
| Set a tag on a prompt.
|
| This method delegates directly to the store, providing full Unity Catalog support
| when used with Unity Catalog registries.
|
| Args:
| name: Name of the prompt.
| key: Tag key.
| value: Tag value.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| client.set_prompt_tag("my_prompt", "environment", "production")
|
| set_prompt_version_tag(self, name: str, version: str | int, key: str, value: str) -> None
| Set a tag on a specific prompt version.
|
| Args:
| name: The name of the prompt.
| version: The version number of the prompt.
| key: The tag key.
| value: The tag value.
|
| set_registered_model_alias(self, name: str, alias: str, version: str) -> None
| Set a registered model alias pointing to a model version.
|
| Args:
| name: Registered model name.
| alias: Name of the alias. Note that aliases of the format ``v<number>``, such as
| ``v9`` and ``v42``, are reserved and cannot be set.
| version: Registered model version number.
|
| .. code-block:: Python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_info(rm):
| print("--Model--")
| print("name: {}".format(rm.name))
| print("aliases: {}".format(rm.aliases))
|
|
| def print_model_version_info(mv):
| print("--Model Version--")
| print("Name: {}".format(mv.name))
| print("Version: {}".format(mv.version))
| print("Aliases: {}".format(mv.aliases))
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, artifact_path="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
| model = client.get_registered_model(name)
| print_model_info(model)
|
| # Create a new version of the rfr model under the registered model name
| model_uri = "runs:/{}/sklearn-model".format(run.info.run_id)
| mv = client.create_model_version(name, model_uri, run.info.run_id)
| print_model_version_info(mv)
|
| # Set registered model alias
| client.set_registered_model_alias(name, "test-alias", mv.version)
| print()
| print_model_info(model)
| print_model_version_info(mv)
|
| .. code-block:: text
| :caption: Output
|
| --Model--
| name: RandomForestRegression
| aliases: {}
|
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: []
|
| --Model--
| name: RandomForestRegression
| aliases: {"test-alias": "1"}
|
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: ["test-alias"]
|
| set_registered_model_tag(self, name, key, value) -> None
| Set a tag for the registered model.
|
| Args:
| name: Registered model name.
| key: Tag key to log.
| value: Tag value log.
|
| .. code-block:: Python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
|
| def print_model_info(rm):
| print("--")
| print("name: {}".format(rm.name))
| print("tags: {}".format(rm.tags))
|
|
| name = "SocialMediaTextAnalyzer"
| tags = {"nlp.framework1": "Spark NLP"}
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| client = MlflowClient()
|
| # Create registered model, set an additional tag, and fetch
| # update model info
| client.create_registered_model(name, tags, desc)
| model = client.get_registered_model(name)
| print_model_info(model)
| client.set_registered_model_tag(name, "nlp.framework2", "VADER")
| model = client.get_registered_model(name)
| print_model_info(model)
|
| .. code-block:: text
| :caption: Output
|
| --
| name: SocialMediaTextAnalyzer
| tags: {'nlp.framework1': 'Spark NLP'}
| --
| name: SocialMediaTextAnalyzer
| tags: {'nlp.framework1': 'Spark NLP', 'nlp.framework2': 'VADER'}
|
| set_tag(self, run_id: str, key: str, value: Any, synchronous: bool | None = None) -> mlflow.utils.async_logging.run_operations.RunOperations | None
| Set a tag on the run with the specified ID. Value is converted to a string.
|
| Args:
| run_id: String ID of the run.
| key: Tag name. This string may only contain alphanumerics, underscores (_), dashes (-),
| periods (.), spaces ( ), and slashes (/). All backend stores will support keys up to
| length 250, but some may support larger keys.
| value: Tag value, but will be string-ified if not. All backend stores will support
| values up to length 5000, but some may support larger values.
| synchronous: *Experimental* If True, blocks until the metric is logged successfully.
| If False, logs the metric asynchronously and returns a future representing the
| logging operation. If None, read from environment variable
| `MLFLOW_ENABLE_ASYNC_LOGGING`, which defaults to False if not set.
|
| Returns:
| When `synchronous=True` or None, returns None. When `synchronous=False`, returns an
| `mlflow.utils.async_logging.run_operations.RunOperations` instance that represents
| future for logging operation.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_run_info(run):
| print(f"run_id: {run.info.run_id}")
| print(f"Tags: {run.data.tags}")
|
|
| # Create a run under the default experiment (whose id is '0').
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| print_run_info(run)
| print("--")
| # Set a tag and fetch updated run info
| client.set_tag(run.info.run_id, "nlp.framework", "Spark NLP")
| run = client.get_run(run.info.run_id)
| print_run_info(run)
|
| .. code-block:: text
| :caption: Output
|
| run_id: 4f226eb5758145e9b28f78514b59a03b
| Tags: {}
| --
| run_id: 4f226eb5758145e9b28f78514b59a03b
| Tags: {'nlp.framework': 'Spark NLP'}
|
| set_terminated(self, run_id: str, status: str | None = None, end_time: int | None = None) -> None
| Set a run's status to terminated.
|
| Args:
| run_id: The ID of the run to terminate.
| status: A string value of :py:class:`mlflow.entities.RunStatus`. Defaults to "FINISHED".
| end_time: If not provided, defaults to the current time.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
|
| def print_run_info(r):
| print(f"run_id: {r.info.run_id}")
| print(f"status: {r.info.status}")
|
|
| # Create a run under the default experiment (whose id is '0').
| # Since this is low-level CRUD operation, this method will create a run.
| # To end the run, you'll have to explicitly terminate it.
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| print_run_info(run)
| print("--")
|
| # Terminate the run and fetch updated status. By default,
| # the status is set to "FINISHED". Other values you can
| # set are "KILLED", "FAILED", "RUNNING", or "SCHEDULED".
| client.set_terminated(run.info.run_id, status="KILLED")
| run = client.get_run(run.info.run_id)
| print_run_info(run)
|
| .. code-block:: text
|
| run_id: 575fb62af83f469e84806aee24945973
| status: RUNNING
| --
| run_id: 575fb62af83f469e84806aee24945973
| status: KILLED
|
| set_trace_tag(self, trace_id: str, key: str, value: str)
| .. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
|
| Set a tag on the trace with the given trace ID.
|
| The trace can be an active one or the one that has already ended and recorded in the
| backend. Below is an example of setting a tag on an active trace. You can replace the
| ``trace_id`` parameter to set a tag on an already ended trace.
|
| .. code-block:: python
| :test:
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| root_span = client.start_trace("my_trace")
| client.set_trace_tag(root_span.trace_id, "key", "value")
| client.end_trace(root_span.trace_id)
|
| Args:
| trace_id: The ID of the trace to set the tag on.
| key: The string key of the tag. Must be at most 250 characters long, otherwise
| it will be truncated when stored.
| value: The string value of the tag. Must be at most 250 characters long, otherwise
| it will be truncated when stored.
|
| start_span(self, name: str, trace_id: str, parent_id: str, span_type: str = 'UNKNOWN', inputs: typing.Any | None = None, attributes: dict[str, typing.Any] | None = None, start_time_ns: int | None = None, links: list[mlflow.entities.link.Link] | None = None) -> mlflow.entities.span.Span
| .. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
|
| Create a new span and start it without attaching it to the global trace context.
|
| This is an imperative API to manually create a new span under a specific trace id
| and parent span, unlike the higher-level APIs like
| :py:func:`@mlflow.trace <mlflow.trace>` decorator and
| :py:func:`with mlflow.start_span() <mlflow.start_span>` context manager, which
| automatically manage the span lifecycle and parent-child relationship.
|
| This API is useful for the case where the automatic context management is not
| sufficient, such as callback-based instrumentation where span start and end are
| not in the same call stack, or multi-threaded applications where the context is
| not propagated automatically.
|
| This API requires a parent span ID to be provided explicitly. If you haven't
| started any span yet, use the :py:func:`start_trace() <start_trace>` method to
| start a new trace and a root span.
|
| .. warning::
|
| The span created with this method needs to be ended explicitly by calling
| the :py:func:`end_span() <end_span>` method. Otherwise the span will be
| recorded with the incorrect end time and status ``TRACE_STATUS_UNSPECIFIED``.
|
| .. tip::
|
| Instead of creating a root span with the :py:func:`start_trace() <start_trace>`
| method, you can also use this method within the context of a parent span created
| by the fluent APIs like :py:func:`@mlflow.trace <mlflow.trace>` and
| :py:func:`with mlflow.start_span() <mlflow.start_span>`, by passing its span
| ids the parent. This flexibility allows you to use the imperative APIs in
| conjunction with the fluent APIs like below:
|
| .. code-block:: python
| :test:
|
| import mlflow
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| with mlflow.start_span("parent_span") as parent_span:
| child_span = client.start_span(
| name="child_span",
| trace_id=parent_span.trace_id,
| parent_id=parent_span.span_id,
| )
|
| # Do something...
|
| client.end_span(
| trace_id=parent_span.trace_id,
| span_id=child_span.span_id,
| )
|
| However, **the opposite does not work**. You cannot use the fluent APIs within
| the span created by this MlflowClient API. This is because the fluent APIs
| fetches the current span from the managed context, which is not set by the MLflow
| Client APIs. Once you create a span with the MLflow Client APIs, all children
| spans must be created with the MLflow Client APIs. Please be cautious when using
| this mixed approach, as it can lead to unexpected behavior if not used properly.
|
| Args:
| name: The name of the span.
| trace_id: The ID of the trace to attach the span to. This is synonym to
| trace_id` in OpenTelemetry.
| parent_id: The ID of the parent span. The parent span can be a span created by
| both fluent APIs like `with mlflow.start_span()`, and imperative APIs like this.
| span_type: The type of the span. Can be either a string or a
| :py:class:`SpanType <mlflow.entities.SpanType>` enum value.
| inputs: Inputs to set on the span.
| attributes: A dictionary of attributes to set on the span.
| start_time_ns: The start time of the span in nano seconds since the UNIX epoch.
| If not provided, the current time will be used.
| links: A list of :py:class:`Link <mlflow.entities.Link>` objects to associate with
| the span.
|
| Returns:
| An :py:class:`mlflow.entities.Span` object representing the span.
|
| Example:
|
| .. code-block:: python
| :test:
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| span = client.start_trace("my_trace")
|
| x = 2
|
| # Create a child span
| child_span = client.start_span(
| "child_span",
| trace_id=span.trace_id,
| parent_id=span.span_id,
| inputs={"x": x},
| )
|
| y = x**2
|
| client.end_span(
| trace_id=child_span.trace_id,
| span_id=child_span.span_id,
| attributes={"factor": 2},
| outputs={"y": y},
| )
|
| client.end_trace(span.trace_id)
|
| start_trace(self, name: str, span_type: str = 'UNKNOWN', inputs: typing.Any | None = None, attributes: dict[str, str] | None = None, tags: dict[str, str] | None = None, experiment_id: str | None = None, start_time_ns: int | None = None, run_id: str | None = None, links: list[mlflow.entities.link.Link] | None = None) -> mlflow.entities.span.Span
| Create a new trace object and start a root span under it.
|
| This is an imperative API to manually create a new span under a specific trace id and
| parent span, unlike the higher-level APIs like :py:func:`@mlflow.trace <mlflow.trace>`
| and :py:func:`with mlflow.start_span() <mlflow.start_span>`, which automatically manage
| the span lifecycle and parent-child relationship. You only need to call this method
| when using the :py:func:`start_span() <start_span>` method of MlflowClient to create
| spans.
|
| .. attention::
|
| A trace started with this method must be ended by calling
| ``MlflowClient().end_trace(trace_id)``. Otherwise the trace will be not recorded.
|
| Args:
| name: The name of the trace (and the root span).
| span_type: The type of the span.
| inputs: Inputs to set on the root span of the trace.
| attributes: A dictionary of attributes to set on the root span of the trace.
| tags: A dictionary of tags to set on the trace.
| experiment_id: The ID of the experiment to create the trace in. If not provided,
| MLflow will look for valid experiment in the following order: activated using
| :py:func:`mlflow.set_experiment() <mlflow.set_experiment>`,
| ``MLFLOW_EXPERIMENT_NAME`` environment variable, ``MLFLOW_EXPERIMENT_ID``
| environment variable, or the default experiment as defined by the tracking server.
| start_time_ns: The start time of the trace in nanoseconds since the UNIX epoch.
| run_id: The ID of the MLflow run to associate with the trace. If provided, the
| trace will be linked to this run.
| links: A list of :py:class:`Link <mlflow.entities.Link>` objects to associate with
| the root span.
|
| Returns:
| An :py:class:`Span <mlflow.entities.Span>` object
| representing the root span of the trace.
|
| Example:
|
| .. code-block:: python
| :test:
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| root_span = client.start_trace("my_trace")
| trace_id = root_span.trace_id
|
| # Create a child span
| child_span = client.start_span(
| "child_span", trace_id=trace_id, parent_id=root_span.span_id
| )
| # Do something...
| client.end_span(trace_id=trace_id, span_id=child_span.span_id)
|
| client.end_trace(trace_id)
|
| test_webhook(self, webhook_id: str, event: Union[Literal['registered_model.created', 'model_version.created', 'model_version_tag.set', 'model_version_tag.deleted', 'model_version_alias.created', 'model_version_alias.deleted', 'prompt.created', 'prompt_version.created', 'prompt_tag.set', 'prompt_tag.deleted', 'prompt_version_tag.set', 'prompt_version_tag.deleted', 'prompt_alias.created', 'prompt_alias.deleted', 'budget_policy.exceeded'], mlflow.entities.webhook.WebhookEvent, NoneType] = None) -> mlflow.entities.webhook.WebhookTestResult
| Test a webhook by sending a test payload.
|
| Args:
| webhook_id: Webhook ID to test.
| event: Optional event type to test. Can be a WebhookEvent object or a string in
| "entity.action" format (e.g., "model_version.created"). If not specified, uses
| the first event from webhook.
|
| Returns:
| WebhookTestResult indicating success/failure and response details.
|
| transition_model_version_stage(self, name: str, version: str, stage: str, archive_existing_versions: bool = False) -> mlflow.entities.model_registry.model_version.ModelVersion
| .. Warning:: ``mlflow.tracking.client.MlflowClient.transition_model_version_stage`` is deprecated since 2.9.0. Model registry stages will be removed in a future major release. To learn more about the deprecation of model registry stages, see our migration guide here: https://mlflow.org/docs/latest/model-registry.html#migrating-from-stages
|
| Update model version stage.
|
| Args:
| name: Registered model name.
| version: Registered model version.
| stage: New desired stage for this model version.
| archive_existing_versions: If this flag is set to ``True``, all existing model
| versions in the stage will be automatically moved to the "archived" stage. Only
| valid when ``stage`` is ``"staging"`` or ``"production"`` otherwise an error will be
| raised.
|
| Returns:
| A single :py:class:`mlflow.entities.model_registry.ModelVersion` object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_version_info(mv):
| print(f"Name: {mv.name}")
| print(f"Version: {mv.version}")
| print(f"Description: {mv.description}")
| print(f"Stage: {mv.current_stage}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| desc = "A new version of the model using ensemble trees"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a new version of the rfr model under the registered model name
| model_uri = f"runs:/{run.info.run_id}/sklearn-model"
| mv = client.create_model_version(name, model_uri, run.info.run_id, description=desc)
| print_model_version_info(mv)
| print("--")
| # transition model version from None -> staging
| mv = client.transition_model_version_stage(name, mv.version, "staging")
| print_model_version_info(mv)
|
| .. code-block:: text
| :caption: Output
|
| Name: RandomForestRegression
| Version: 1
| Description: A new version of the model using ensemble trees
| Stage: None
| --
| Name: RandomForestRegression
| Version: 1
| Description: A new version of the model using ensemble trees
| Stage: Staging
|
| unlink_traces_from_run(self, trace_ids: list[str], run_id: str) -> None
| Unlink multiple traces from a run by removing entity associations.
|
| Args:
| trace_ids: List of trace IDs to unlink from the run.
| run_id: ID of the run to unlink traces from.
|
| Example:
| .. code-block:: python
|
| import mlflow
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Unlink multiple V4 traces from a run
| client.unlink_traces_from_run(
| trace_ids=[
| "trace://catalog.schema/abc123",
| "trace://catalog.schema/def456",
| ],
| run_id="run_abc",
| )
|
| update_mcp_access_endpoint(self, server_name: str, endpoint_id: str, url: str | None = <object object at 0x0000025F348EA210>, transport_type: mlflow.entities.mcp_server.MCPRemoteTransportType | None = <object object at 0x0000025F348EA210>, server_version: str | None = <object object at 0x0000025F348EA210>, server_alias: str | None = <object object at 0x0000025F348EA210>) -> mlflow.entities.mcp_access_endpoint.MCPAccessEndpoint
|
| update_mcp_server(self, name: str, display_name: str | None = <object object at 0x0000025F348EA210>, description: str | None = <object object at 0x0000025F348EA210>, icons: list[mlflow.store.tracking.mcp_server_registry.abstract_mixin.MCPIcon] | None = <object object at 0x0000025F348EA210>) -> mlflow.entities.mcp_server.MCPServer
|
| update_mcp_server_version(self, name: str, version: str, status: mlflow.entities.mcp_server.MCPStatus | None = <object object at 0x0000025F348EA210>, tools: list[mlflow.entities.mcp_server.MCPTool] | None = <object object at 0x0000025F348EA210>, connect_options: dict[str, mlflow.entities.mcp_server_version.ConnectOptionSettings] | None = <object object at 0x0000025F348EA210>) -> mlflow.entities.mcp_server_version.MCPServerVersion
|
| update_model_version(self, name: str, version: str, description: str | None = None) -> mlflow.entities.model_registry.model_version.ModelVersion
| Update metadata associated with a model version in backend.
|
| Args:
| name: Name of the containing registered model.
| version: Version number of the model version.
| description: New description.
|
| Returns:
| A single :py:class:`mlflow.entities.model_registry.ModelVersion` object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_version_info(mv):
| print(f"Name: {mv.name}")
| print(f"Version: {mv.version}")
| print(f"Description: {mv.description}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
| # Create a new version of the rfr model under the registered model name
| model_uri = f"runs:/{run.info.run_id}/sklearn-model"
| mv = client.create_model_version(name, model_uri, run.info.run_id)
| print_model_version_info(mv)
| print("--")
| # Update model version's description
| desc = "A new version of the model using ensemble trees"
| mv = client.update_model_version(name, mv.version, desc)
| print_model_version_info(mv)
|
| .. code-block:: text
| :caption: Output
|
| Name: RandomForestRegression
| Version: 1
| Description: None
| --
| Name: RandomForestRegression
| Version: 1
| Description: A new version of the model using ensemble trees
|
| update_registered_model(self, name: str, description: str | None = None, deployment_job_id: str | None = None) -> mlflow.entities.model_registry.registered_model.RegisteredModel
| Updates metadata for RegisteredModel entity. Input field ``description`` should be non-None.
| Backend raises exception if a registered model with given name does not exist.
|
| Args:
| name: Name of the registered model to update.
| description: (Optional) New description.
| deployment_job_id: Optional deployment job ID.
|
| Returns:
| A single updated :py:class:`mlflow.entities.model_registry.RegisteredModel` object.
|
| .. code-block:: python
| :caption: Example
|
| def print_registered_model_info(rm):
| print(f"name: {rm.name}")
| print(f"tags: {rm.tags}")
| print(f"description: {rm.description}")
|
|
| name = "SocialMediaTextAnalyzer"
| tags = {"nlp.framework": "Spark NLP"}
| desc = "This sentiment analysis model classifies the tone-happy, sad, angry."
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| client = MlflowClient()
| client.create_registered_model(name, tags, desc)
| print_registered_model_info(client.get_registered_model(name))
| print("--")
|
| # Update the model's description
| desc = "This sentiment analysis model classifies tweets' tone: happy, sad, angry."
| client.update_registered_model(name, desc)
| print_registered_model_info(client.get_registered_model(name))
|
| .. code-block:: text
| :caption: Output
|
| name: SocialMediaTextAnalyzer
| tags: {'nlp.framework': 'Spark NLP'}
| description: This sentiment analysis model classifies the tone-happy, sad, angry.
| --
| name: SocialMediaTextAnalyzer
| tags: {'nlp.framework': 'Spark NLP'}
| description: This sentiment analysis model classifies tweets' tone: happy, sad, angry.
|
| update_run(self, run_id: str, status: str | None = None, name: str | None = None) -> None
| Update a run with the specified ID to a new status or name.
|
| Args:
| run_id: The ID of the Run to update.
| status: The new status of the run to set, if specified. At least one of ``status`` or
| ``name`` should be specified.
| name: The new name of the run to set, if specified. At least one of ``name`` or
| ``status`` should be specified.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_run_info(run):
| print(f"run_id: {run.info.run_id}")
| print(f"run_name: {run.info.run_name}")
| print(f"status: {run.info.status}")
|
|
| # Create a run under the default experiment (whose id is '0').
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| print_run_info(run)
| print("--")
|
| # Update run and fetch info
| client.update_run(run.info.run_id, "FINISHED", "new_name")
| run = client.get_run(run.info.run_id)
| print_run_info(run)
|
| .. code-block:: text
| :caption: Output
|
| run_id: 1cf6bf8bf6484dd8a598bd43be367b20
| run_name: judicious-hog-915
| status: RUNNING
| --
| run_id: 1cf6bf8bf6484dd8a598bd43be367b20
| run_name: new_name
| status: FINISHED
|
| update_webhook(self, webhook_id: str, name: str | None = None, description: str | None = None, url: str | None = None, events: list[typing.Union[typing.Literal['registered_model.created', 'model_version.created', 'model_version_tag.set', 'model_version_tag.deleted', 'model_version_alias.created', 'model_version_alias.deleted', 'prompt.created', 'prompt_version.created', 'prompt_tag.set', 'prompt_tag.deleted', 'prompt_version_tag.set', 'prompt_version_tag.deleted', 'prompt_alias.created', 'prompt_alias.deleted', 'budget_policy.exceeded'], mlflow.entities.webhook.WebhookEvent]] | None = None, secret: str | None = None, status: str | mlflow.entities.webhook.WebhookStatus | None = None) -> mlflow.entities.webhook.Webhook
| Update an existing webhook.
|
| Args:
| webhook_id: Webhook ID.
| name: New webhook name.
| description: New webhook description.
| url: New webhook URL.
| events: New list of events. Can be strings or `WebhookEvent` objects.
| secret: New webhook secret.
| status: New webhook status. Can be string or WebhookStatus enum.
| Valid statuses: "ACTIVE", "DISABLED"
|
| Returns:
| A :py:class:`mlflow.entities.webhook.Webhook` object representing the updated webhook.
|
| update_workspace(self, name: str, description: str | None = None, default_artifact_root: str | None = None, trace_archival_config: mlflow.entities.workspace.TraceArchivalConfig | None = None) -> mlflow.entities.workspace.Workspace
| Update metadata for an existing workspace.
|
| Args:
| name: The name of the workspace to update.
| description: New description, or ``None`` to leave unchanged.
| default_artifact_root: New artifact root URI, empty string to clear, or ``None``.
| trace_archival_config: Optional Python-side grouping for trace archival settings.
| Use ``TraceArchivalConfig.location`` to update the archival storage URI/root and
| ``TraceArchivalConfig.retention`` to update the archived-trace retention duration
| such as ``30d`` or ``12h``. Use an empty string to clear an existing value, or
| leave fields as ``None`` to keep the current value unchanged.
|
| Returns:
| The updated workspace.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| tracking_uri
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
mlflow.MlflowException
Python Library Documentation: class MlflowException in module mlflow.exceptions class MlflowException(builtins.Exception) | MlflowException(message: str, error_code: int = 1, sqlstate: str | None = None, error_class: str | None = None, **kwargs) | | Generic exception thrown to surface failure information about external-facing operations. | The error message associated with this exception may be exposed to clients in HTTP responses | for debugging purposes. If the error text is sensitive, raise a generic `Exception` object | instead. | | Method resolution order: | MlflowException | builtins.Exception | builtins.BaseException | builtins.object | | Methods defined here: | | __init__(self, message: str, error_code: int = 1, sqlstate: str | None = None, error_class: str | None = None, **kwargs) | Args: | message: The message or exception describing the error that occurred. This will be | included in the exception's serialized JSON representation. | error_code: An appropriate error code for the error that occurred; it will be | included in the exception's serialized JSON representation. This should | be one of the codes listed in the `mlflow.protos.databricks_pb2` proto. | sqlstate: A 5-character SQLSTATE code for error classification. If not provided, | auto-derived from error_code. | error_class: A descriptive error class name (e.g., "SCHEMA_ENFORCEMENT_FAILED"). | If not provided, auto-derived from error_code. | kwargs: Additional key-value pairs to include in the serialized JSON representation | of the MlflowException. | | get_http_status_code(self) | | serialize_as_json(self) | | ---------------------------------------------------------------------- | Class methods defined here: | | invalid_parameter_value(message: str, sqlstate: str | None = None, error_class: str | None = None, **kwargs) | Constructs an `MlflowException` object with the `INVALID_PARAMETER_VALUE` error code. | | Args: | message: The message describing the error that occurred. This will be included in the | exception's serialized JSON representation. | sqlstate: A 5-character SQLSTATE code for error classification. | error_class: A descriptive error class name. | kwargs: Additional key-value pairs to include in the serialized JSON representation | of the MlflowException. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __weakref__ | list of weak references to the object | | ---------------------------------------------------------------------- | Static methods inherited from builtins.Exception: | | __new__(*args, **kwargs) class method of builtins.Exception | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from builtins.BaseException: | | __getattribute__(self, name, /) | Return getattr(self, name). | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | __setstate__(...) | | __str__(self, /) | Return str(self). | | add_note(...) | Exception.add_note(note) -- | add a note to the exception | | with_traceback(...) | Exception.with_traceback(tb) -- | set self.__traceback__ to tb and return self. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.BaseException: | | __cause__ | exception cause | | __context__ | exception context | | __dict__ | | __suppress_context__ | | __traceback__ | | args
mlflow.RunOperations
Python Library Documentation: class RunOperations in module mlflow.utils.async_logging.run_operations class RunOperations(builtins.object) | RunOperations(operation_futures) | | Class that helps manage the futures of MLflow async logging. | | Methods defined here: | | __init__(self, operation_futures) | Initialize self. See help(type(self)) for accurate signature. | | wait(self) | Blocks on completion of all futures. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
mlflow.TYPE_CHECKING
Python Library Documentation: bool object class bool(int) | bool(x) -> bool | | Returns True when the argument x is true, False otherwise. | The builtins True and False are the only two instances of the class bool. | The class bool is a subclass of the class int, and cannot be subclassed. | | Method resolution order: | bool | int | object | | Methods defined here: | | __and__(self, value, /) | Return self&value. | | __invert__(self, /) | ~self | | __or__(self, value, /) | Return self|value. | | __rand__(self, value, /) | Return value&self. | | __repr__(self, /) | Return repr(self). | | __ror__(self, value, /) | Return value|self. | | __rxor__(self, value, /) | Return value^self. | | __xor__(self, value, /) | Return self^value. | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from int: | | __abs__(self, /) | abs(self) | | __add__(self, value, /) | Return self+value. | | __bool__(self, /) | True if self else False | | __ceil__(...) | Ceiling of an Integral returns itself. | | __divmod__(self, value, /) | Return divmod(self, value). | | __eq__(self, value, /) | Return self==value. | | __float__(self, /) | float(self) | | __floor__(...) | Flooring an Integral returns itself. | | __floordiv__(self, value, /) | Return self//value. | | __format__(self, format_spec, /) | Convert to a string according to format_spec. | | __ge__(self, value, /) | Return self>=value. | | __getattribute__(self, name, /) | Return getattr(self, name). | | __getnewargs__(self, /) | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __index__(self, /) | Return self converted to an integer, if self is suitable for use as an index into a list. | | __int__(self, /) | int(self) | | __le__(self, value, /) | Return self<=value. | | __lshift__(self, value, /) | Return self<<value. | | __lt__(self, value, /) | Return self<value. | | __mod__(self, value, /) | Return self%value. | | __mul__(self, value, /) | Return self*value. | | __ne__(self, value, /) | Return self!=value. | | __neg__(self, /) | -self | | __pos__(self, /) | +self | | __pow__(self, value, mod=None, /) | Return pow(self, value, mod). | | __radd__(self, value, /) | Return value+self. | | __rdivmod__(self, value, /) | Return divmod(value, self). | | __rfloordiv__(self, value, /) | Return value//self. | | __rlshift__(self, value, /) | Return value<<self. | | __rmod__(self, value, /) | Return value%self. | | __rmul__(self, value, /) | Return value*self. | | __round__(...) | Rounding an Integral returns itself. | | Rounding with an ndigits argument also returns an integer. | | __rpow__(self, value, mod=None, /) | Return pow(value, self, mod). | | __rrshift__(self, value, /) | Return value>>self. | | __rshift__(self, value, /) | Return self>>value. | | __rsub__(self, value, /) | Return value-self. | | __rtruediv__(self, value, /) | Return value/self. | | __sizeof__(self, /) | Returns size in memory, in bytes. | | __sub__(self, value, /) | Return self-value. | | __truediv__(self, value, /) | Return self/value. | | __trunc__(...) | Truncating an Integral returns itself. | | as_integer_ratio(self, /) | Return a pair of integers, whose ratio is equal to the original int. | | The ratio is in lowest terms and has a positive denominator. | | >>> (10).as_integer_ratio() | (10, 1) | >>> (-10).as_integer_ratio() | (-10, 1) | >>> (0).as_integer_ratio() | (0, 1) | | bit_count(self, /) | Number of ones in the binary representation of the absolute value of self. | | Also known as the population count. | | >>> bin(13) | '0b1101' | >>> (13).bit_count() | 3 | | bit_length(self, /) | Number of bits necessary to represent self in binary. | | >>> bin(37) | '0b100101' | >>> (37).bit_length() | 6 | | conjugate(...) | Returns self, the complex conjugate of any int. | | is_integer(self, /) | Returns True. Exists for duck type compatibility with float.is_integer. | | to_bytes(self, /, length=1, byteorder='big', *, signed=False) | Return an array of bytes representing an integer. | | length | Length of bytes object to use. An OverflowError is raised if the | integer is not representable with the given number of bytes. Default | is length 1. | byteorder | The byte order used to represent the integer. If byteorder is 'big', | the most significant byte is at the beginning of the byte array. If | byteorder is 'little', the most significant byte is at the end of the | byte array. To request the native byte order of the host system, use | `sys.byteorder' as the byte order value. Default is to use 'big'. | signed | Determines whether two's complement is used to represent the integer. | If signed is False and a negative integer is given, an OverflowError | is raised. | | ---------------------------------------------------------------------- | Class methods inherited from int: | | from_bytes(bytes, byteorder='big', *, signed=False) | Return the integer represented by the given array of bytes. | | bytes | Holds the array of bytes to convert. The argument must either | support the buffer protocol or be an iterable object producing bytes. | Bytes and bytearray are examples of built-in objects that support the | buffer protocol. | byteorder | The byte order used to represent the integer. If byteorder is 'big', | the most significant byte is at the beginning of the byte array. If | byteorder is 'little', the most significant byte is at the end of the | byte array. To request the native byte order of the host system, use | `sys.byteorder' as the byte order value. Default is to use 'big'. | signed | Indicates whether two's complement is used to represent the integer. | | ---------------------------------------------------------------------- | Data descriptors inherited from int: | | denominator | the denominator of a rational number in lowest terms | | imag | the imaginary part of a complex number | | numerator | the numerator of a rational number in lowest terms | | real | the real part of a complex number
mlflow.VERSION
Error rendering doc: No Python documentation found for '3.15.0'. Use help() to get the interactive help utility. Use help(str) for help on the str class.
mlflow.active_run
Python Library Documentation: function active_run in module mlflow.tracking.fluent
active_run() -> mlflow.tracking.fluent.ActiveRun | None
Get the currently active ``Run``, or None if no such run exists.
.. attention::
This API is **thread-local** and returns only the active run in the current thread.
If your application is multi-threaded and a run is started in a different thread,
this API will not retrieve that run.
**Note**: You cannot access currently-active run attributes
(parameters, metrics, etc.) through the run returned by ``mlflow.active_run``. In order
to access such attributes, use the :py:class:`mlflow.client.MlflowClient` as follows:
.. code-block:: python
:test:
:caption: Example
import mlflow
mlflow.start_run()
run = mlflow.active_run()
print(f"Active run_id: {run.info.run_id}")
mlflow.end_run()
.. code-block:: text
:caption: Output
Active run_id: 6f252757005748708cd3aad75d1ff462
mlflow.add_trace
Python Library Documentation: function add_trace in module mlflow.tracing.fluent
add_trace(trace: 'Trace | dict[str, Any]', target: 'LiveSpan | None' = None)
Add a completed trace object into another trace.
This is particularly useful when you call a remote service instrumented by
MLflow Tracing. By using this function, you can merge the trace from the remote
service into the current active local trace, so that you can see the full
trace including what happens inside the remote service call.
The following example demonstrates how to use this function to merge a trace from a remote
service to the current active trace in the function.
.. code-block:: python
@mlflow.trace(name="predict")
def predict(input):
# Call a remote service that returns a trace in the response
resp = requests.get("https://your-service-endpoint", ...)
# Extract the trace from the response
trace_json = resp.json().get("trace")
# Use the remote trace as a part of the current active trace.
# It will be merged under the span "predict" and exported together when it is ended.
mlflow.add_trace(trace_json)
If you have a specific target span to merge the trace under, you can pass the target span
.. code-block:: python
def predict(input):
# Create a local span
with mlflow.start_span(name="predict") as span:
resp = requests.get("https://your-service-endpoint", ...)
trace_json = resp.json().get("trace")
# Merge the remote trace under the span created above
mlflow.add_trace(trace_json, target=span)
Args:
trace: A :py:class:`Trace <mlflow.entities.Trace>` object or a dictionary representation
of the trace. The trace **must** be already completed i.e. no further updates should
be made to it. Otherwise, this function will raise an exception.
.. attention:
The spans in the trace must be ordered in a way that the parent span comes
before its children. If the spans are not ordered correctly, this function
will raise an exception.
target: The target span to merge the given trace.
- If provided, the trace will be merged under the target span.
- If not provided, the trace will be merged under the current active span.
- If not provided and there is no active span, a new span named "Remote Trace <...>"
will be created and the trace will be merged under it.
mlflow.ag2
Python Library Documentation: package mlflow.ag2 in mlflow
NAME
mlflow.ag2
PACKAGE CONTENTS
ag2_logger
DATA
FLAVOR_NAME = 'ag2'
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\ag2\__init__.py
mlflow.agno
Python Library Documentation: package mlflow.agno in mlflow
NAME
mlflow.agno
PACKAGE CONTENTS
autolog_v1
autolog_v2
utils
DATA
FLAVOR_NAME = 'agno'
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\agno\__init__.py
mlflow.anthropic
Python Library Documentation: package mlflow.anthropic in mlflow
NAME
mlflow.anthropic
PACKAGE CONTENTS
autolog
chat
genai_semconv_converter
DATA
FLAVOR_NAME = 'anthropic'
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\anthropic\__init__.py
mlflow.artifacts
Python Library Documentation: package mlflow.artifacts in mlflow
NAME
mlflow.artifacts - APIs for interacting with artifacts in MLflow
PACKAGE CONTENTS
FUNCTIONS
download_artifacts(artifact_uri: str | None = None, run_id: str | None = None, artifact_path: str | None = None, dst_path: str | None = None, tracking_uri: str | None = None, registry_uri: str | None = None) -> str
Download an artifact file or directory to a local directory.
Args:
artifact_uri: URI pointing to the artifacts. Supported formats include:
* ``runs:/<run_id>/<artifact_path>``
Example: ``runs:/500cf58bee2b40a4a82861cc31a617b1/my_model.pkl``
* ``models:/<model_name>/<stage>``
Example: ``models:/my_model/Production``
* ``models:/<model_name>/<version>/path/to/model``
Example: ``models:/my_model/2/path/to/model``
* ``models:/<model_name>@<alias>/path/to/model``
Example: ``models:/my_model@staging/path/to/model``
* Cloud storage URIs: ``s3://<bucket>/<path>`` or ``gs://<bucket>/<path>``
* Tracking server artifact URIs: ``http://<host>/mlartifacts`` or
``mlflow-artifacts://<host>/mlartifacts``
Exactly one of ``artifact_uri`` or ``run_id`` must be specified.
run_id: ID of the MLflow Run containing the artifacts. Exactly one of ``run_id`` or
``artifact_uri`` must be specified.
artifact_path: (For use with ``run_id``) If specified, a path relative to the MLflow
Run's root directory containing the artifacts to download.
dst_path: Path of the local filesystem destination directory to which to download the
specified artifacts. If the directory does not exist, it is created. If
unspecified, the artifacts are downloaded to a new uniquely-named directory on
the local filesystem, unless the artifacts already exist on the local
filesystem, in which case their local path is returned directly.
tracking_uri: The tracking URI to be used when downloading artifacts.
registry_uri: The registry URI to be used when downloading artifacts.
Returns:
The location of the artifact file or directory on the local filesystem.
list_artifacts(artifact_uri: str | None = None, run_id: str | None = None, artifact_path: str | None = None, tracking_uri: str | None = None) -> list[mlflow.entities.file_info.FileInfo]
List artifacts at the specified URI.
Args:
artifact_uri: URI pointing to the artifacts, such as
``"runs:/500cf58bee2b40a4a82861cc31a617b1/my_model.pkl"``,
``"models:/my_model/Production"``, or ``"s3://my_bucket/my/file.txt"``.
Exactly one of ``artifact_uri`` or ``run_id`` must be specified.
run_id: ID of the MLflow Run containing the artifacts. Exactly one of ``run_id`` or
``artifact_uri`` must be specified.
artifact_path: (For use with ``run_id``) If specified, a path relative to the MLflow
Run's root directory containing the artifacts to list.
tracking_uri: The tracking URI to be used when list artifacts.
Returns:
List of artifacts as FileInfo listed directly under path.
load_dict(artifact_uri: str) -> dict[str, typing.Any]
Loads the artifact contents as a dictionary.
Args:
artifact_uri: artifact location.
Returns:
A dictionary.
.. code-block:: python
:caption: Example
import mlflow
with mlflow.start_run() as run:
artifact_uri = run.info.artifact_uri
mlflow.log_dict({"mlflow-version": "0.28", "n_cores": "10"}, "config.json")
config_json = mlflow.artifacts.load_dict(artifact_uri + "/config.json")
print(config_json)
.. code-block:: text
:caption: Output
{'mlflow-version': '0.28', 'n_cores': '10'}
load_image(artifact_uri: str)
Loads artifact contents as a ``PIL.Image.Image`` object
Args:
artifact_uri: Artifact location.
Returns:
A PIL.Image object.
.. code-block:: python
:caption: Example
import mlflow
from PIL import Image
with mlflow.start_run() as run:
image = Image.new("RGB", (100, 100))
artifact_uri = run.info.artifact_uri
mlflow.log_image(image, "image.png")
image = mlflow.artifacts.load_image(artifact_uri + "/image.png")
print(image)
.. code-block:: text
:caption: Output
<PIL.PngImagePlugin.PngImageFile image mode=RGB size=100x100 at 0x11D2FA3D0>
load_text(artifact_uri: str) -> str
Loads the artifact contents as a string.
Args:
artifact_uri: Artifact location.
Returns:
The contents of the artifact as a string.
.. code-block:: python
:caption: Example
import mlflow
with mlflow.start_run() as run:
artifact_uri = run.info.artifact_uri
mlflow.log_text("This is a sentence", "file.txt")
file_content = mlflow.artifacts.load_text(artifact_uri + "/file.txt")
print(file_content)
.. code-block:: text
:caption: Output
This is a sentence
DATA
BAD_REQUEST = 4
INVALID_PARAMETER_VALUE = 1000
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\artifacts\__init__.py
mlflow.autogen
Python Library Documentation: package mlflow.autogen in mlflow
NAME
mlflow.autogen
PACKAGE CONTENTS
chat
DATA
FLAVOR_NAME = 'autogen'
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\autogen\__init__.py
mlflow.autolog
Python Library Documentation: function autolog in module mlflow.tracking.fluent
autolog(log_input_examples: bool = False, log_model_signatures: bool = True, log_models: bool = True, log_datasets: bool = True, log_traces: bool = True, disable: bool = False, exclusive: bool = False, disable_for_unsupported_versions: bool = False, silent: bool = False, extra_tags: dict[str, str] | None = None, exclude_flavors: list[str] | None = None) -> None
Enables (or disables) and configures autologging for all supported integrations.
The parameters are passed to any autologging integrations that support them.
See the `tracking docs <../../tracking/autolog.html>`_ for a list of supported autologging
integrations.
Note that framework-specific configurations set at any point will take precedence over
any configurations set by this function. For example:
.. code-block:: python
:test:
import mlflow
mlflow.autolog(log_models=False, exclusive=True)
import sklearn
would enable autologging for `sklearn` with `log_models=False` and `exclusive=True`,
but
.. code-block:: python
:test:
import mlflow
mlflow.autolog(log_models=False, exclusive=True)
import sklearn
mlflow.sklearn.autolog(log_models=True)
would enable autologging for `sklearn` with `log_models=True` and `exclusive=False`,
the latter resulting from the default value for `exclusive` in `mlflow.sklearn.autolog`;
other framework autolog functions (e.g. `mlflow.tensorflow.autolog`) would use the
configurations set by `mlflow.autolog` (in this instance, `log_models=False`, `exclusive=True`),
until they are explicitly called by the user.
Args:
log_input_examples: If ``True``, input examples from training datasets are collected and
logged along with model artifacts during training. If ``False``,
input examples are not logged.
Note: Input examples are MLflow model attributes
and are only collected if ``log_models`` is also ``True``.
log_model_signatures: If ``True``,
:py:class:`ModelSignatures <mlflow.models.ModelSignature>`
describing model inputs and outputs are collected and logged along
with model artifacts during training. If ``False``, signatures are
not logged. Note: Model signatures are MLflow model attributes
and are only collected if ``log_models`` is also ``True``.
log_models: If ``True``, trained models are logged as MLflow model artifacts.
If ``False``, trained models are not logged.
Input examples and model signatures, which are attributes of MLflow models,
are also omitted when ``log_models`` is ``False``.
log_datasets: If ``True``, dataset information is logged to MLflow Tracking.
If ``False``, dataset information is not logged.
log_traces: If ``True``, traces are collected for integrations.
If ``False``, no trace is collected.
disable: If ``True``, disables all supported autologging integrations. If ``False``,
enables all supported autologging integrations.
exclusive: If ``True``, autologged content is not logged to user-created fluent runs.
If ``False``, autologged content is logged to the active fluent run,
which may be user-created.
disable_for_unsupported_versions: If ``True``, disable autologging for versions of
all integration libraries that have not been tested against this version
of the MLflow client or are incompatible.
silent: If ``True``, suppress all event logs and warnings from MLflow during autologging
setup and training execution. If ``False``, show all events and warnings during
autologging setup and training execution.
extra_tags: A dictionary of extra tags to set on each managed run created by autologging.
exclude_flavors: A list of flavor names that are excluded from the auto-logging.
e.g. tensorflow, pyspark.ml
.. code-block:: python
:test:
:caption: Example
import numpy as np
import mlflow.sklearn
from mlflow import MlflowClient
from sklearn.linear_model import LinearRegression
def print_auto_logged_info(r):
tags = {k: v for k, v in r.data.tags.items() if not k.startswith("mlflow.")}
artifacts = [f.path for f in MlflowClient().list_artifacts(r.info.run_id, "model")]
print(f"run_id: {r.info.run_id}")
print(f"artifacts: {artifacts}")
print(f"params: {r.data.params}")
print(f"metrics: {r.data.metrics}")
print(f"tags: {tags}")
# prepare training data
X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]])
y = np.dot(X, np.array([1, 2])) + 3
# Auto log all the parameters, metrics, and artifacts
mlflow.autolog()
model = LinearRegression()
with mlflow.start_run() as run:
model.fit(X, y)
# fetch the auto logged parameters and metrics for ended run
print_auto_logged_info(mlflow.get_run(run_id=run.info.run_id))
.. code-block:: text
:caption: Output
run_id: fd10a17d028c47399a55ab8741721ef7
artifacts: ['model/MLmodel', 'model/conda.yaml', 'model/model.pkl']
params: {'copy_X': 'True',
'normalize': 'False',
'fit_intercept': 'True',
'n_jobs': 'None'}
metrics: {'training_score': 1.0,
'training_root_mean_squared_error': 4.440892098500626e-16,
'training_r2_score': 1.0,
'training_mean_absolute_error': 2.220446049250313e-16,
'training_mean_squared_error': 1.9721522630525295e-31}
tags: {'estimator_class': 'sklearn.linear_model._base.LinearRegression',
'estimator_name': 'LinearRegression'}
mlflow.azure
Python Library Documentation: package mlflow.azure in mlflow
NAME
mlflow.azure
PACKAGE CONTENTS
client
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\azure\__init__.py
mlflow.bedrock
Python Library Documentation: package mlflow.bedrock in mlflow
NAME
mlflow.bedrock
PACKAGE CONTENTS
_autolog
chat
genai_semconv_converter
stream
utils
DATA
FLAVOR_NAME = 'bedrock'
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\bedrock\__init__.py
mlflow.catboost
Python Library Documentation: package mlflow.catboost in mlflow
NAME
mlflow.catboost
DESCRIPTION
The ``mlflow.catboost`` module provides an API for logging and loading CatBoost models.
This module exports CatBoost models with the following flavors:
CatBoost (native) format
This is the main flavor that can be loaded back into CatBoost.
:py:mod:`mlflow.pyfunc`
Produced for use by generic pyfunc-based deployment tools and batch inference.
.. _CatBoost:
https://catboost.ai/docs/concepts/python-reference_catboost.html
.. _CatBoost.save_model:
https://catboost.ai/docs/concepts/python-reference_catboost_save_model.html
.. _CatBoostClassifier:
https://catboost.ai/docs/concepts/python-reference_catboostclassifier.html
.. _CatBoostRanker:
https://catboost.ai/docs/concepts/python-reference_catboostranker.html
.. _CatBoostRegressor:
https://catboost.ai/docs/concepts/python-reference_catboostregressor.html
PACKAGE CONTENTS
DATA
DEFAULT_AWAIT_MAX_SLEEP_SECONDS = 300
FLAVOR_NAME = 'catboost'
LOG_MODEL_PARAM_DOCS = ParamDocs({'name': 'Model name.', 'conda_env': ...
MLMODEL_FILE_NAME = 'MLmodel'
ModelInputExample = typing.Union[pandas.core.frame.DataFrame, numpy......
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\catboost\__init__.py
mlflow.clear_active_model
Python Library Documentation: function clear_active_model in module mlflow.tracking.fluent
clear_active_model() -> None
Clear the active model. This will clear the active model previously set by
:py:func:`mlflow.set_active_model` or via the ``MLFLOW_ACTIVE_MODEL_ID`` environment variable
or the ``_MLFLOW_ACTIVE_MODEL_ID`` legacy environment variable.
from current thread. To temporarily switch
the active model, use ``with mlflow.set_active_model(...)`` instead.
.. code-block:: python
:test:
:caption: Example
import mlflow
# Set the active model by name
mlflow.set_active_model(name="my_model")
# Clear the active model
mlflow.clear_active_model()
# Check that the active model is None
assert mlflow.get_active_model_id() is None
# If you want to temporarily set the active model,
# use `set_active_model` as a context manager instead
with mlflow.set_active_model(name="my_model") as active_model:
assert mlflow.get_active_model_id() == active_model.model_id
assert mlflow.get_active_model_id() is None
mlflow.client
Python Library Documentation: module mlflow.client in mlflow
NAME
mlflow.client
DESCRIPTION
The ``mlflow.client`` module provides a Python CRUD interface to MLflow Experiments, Runs,
Model Versions, and Registered Models. This is a lower level API that directly translates to MLflow
`REST API <../rest-api.html>`_ calls.
For a higher level API for managing an "active run", use the :py:mod:`mlflow` module.
CLASSES
builtins.object
mlflow.tracking.client.MlflowClient
class MlflowClient(builtins.object)
| MlflowClient(tracking_uri: str | None = None, registry_uri: str | None = None, workspace_store_uri: str | None = None)
|
| Client of an MLflow Tracking Server that creates and manages experiments and runs, and of an
| MLflow Registry Server that creates and manages registered models and model versions. It also
| exposes workspace CRUD via the configured workspace provider. It's a thin wrapper around:
|
| - TrackingServiceClient for tracking operations
| - WorkspaceProviderClient for workspace operations
| - ModelRegistryClient for registry operations
|
| This layered structure provides a unified API while preserving independent implementations.
|
| Methods defined here:
|
| __init__(self, tracking_uri: str | None = None, registry_uri: str | None = None, workspace_store_uri: str | None = None)
| Args:
| tracking_uri: Address of local or remote tracking server. If not provided, defaults
| to the service set by ``mlflow.tracking.set_tracking_uri``. See
| `Where Runs Get Recorded <../tracking.html#where-runs-get-recorded>`_
| for more info.
| registry_uri: Address of local or remote model registry server. If not provided,
| defaults to the service set by ``mlflow.tracking.set_registry_uri``. If
| no such service was set, defaults to the tracking uri of the client.
| workspace_store_uri: Address of the workspace provider backend. Defaults to the tracking
| URI when unspecified, but can be pointed at a dedicated workspace store.
|
| add_dataset_to_experiments(self, dataset_id: str, experiment_ids: list[str]) -> mlflow.entities.evaluation_dataset.EvaluationDataset
| Add a dataset to additional experiments.
|
| This allows reusing datasets across multiple experiments for evaluation purposes.
|
| Args:
| dataset_id: The ID of the dataset to update.
| experiment_ids: List of experiment IDs to associate with the dataset.
|
| Returns:
| The updated EvaluationDataset with new experiment associations.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Add dataset to new experiments
| dataset = client.add_dataset_to_experiments(
| dataset_id="d-abc123", experiment_ids=["1", "2", "3"]
| )
| print(f"Dataset now associated with {len(dataset.experiment_ids)} experiments")
|
| copy_model_version(self, src_model_uri, dst_name) -> mlflow.entities.model_registry.model_version.ModelVersion
| Copy a model version from one registered model to another as a new model version.
| If the destination model does not exist, it will be created.
|
| This method can also be used to migrate model versions from the Databricks workspace
| registry to Unity Catalog. During the migration, signature validation can be bypassed
| by setting the `MLFLOW_SKIP_SIGNATURE_CHECK_FOR_UC_REGISTRY_MIGRATION`environment
| variable to `True`.
|
| Args:
| src_model_uri: The model URI of the model version to copy. This must be a model
| registry URI with a `"models:/"` scheme (e.g., `"models:/iris_model@champion"`).
| dst_name: The name of the registered model to copy the model version to. If a
| registered model with this name does not exist, it will be created.
|
| Returns:
| Single :py:class:`mlflow.entities.model_registry.ModelVersion` object representing
| the copied model version.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_version_info(mv):
| print(f"Name: {mv.name}")
| print(f"Version: {mv.version}")
| print(f"Source: {mv.source}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
|
| # Log a model
| with mlflow.start_run() as run:
| params = {"n_estimators": 3, "random_state": 42}
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Create source model version
| client = MlflowClient()
| src_name = "RandomForestRegression-staging"
| client.create_registered_model(src_name)
| src_uri = f"runs:/{run.info.run_id}/sklearn-model"
| mv_src = client.create_model_version(src_name, src_uri, run.info.run_id)
| print_model_version_info(mv_src)
| print("--")
|
| # Copy the source model version into a new registered model
| dst_name = "RandomForestRegression-production"
| src_model_uri = f"models:/{mv_src.name}/{mv_src.version}"
| mv_copy = client.copy_model_version(src_model_uri, dst_name)
| print(f"Name: {mv_copy.name}, Version: {mv_copy.version}, Source: {mv_copy.source}")
|
| .. code-block:: python
| :caption: Migration example from Databricks Workspace Model Registry to Unity Catalog
|
| from mlflow import MlflowClient
| import os
|
| os.environ["MLFLOW_SKIP_SIGNATURE_CHECK_FOR_UC_REGISTRY_MIGRATION"] = "true"
| client = MlflowClient(registry_uri="databricks")
|
| src_model_uri = f"models:/my_workspace_model/1"
| uc_model_dst_name = "mycatalog.myschema.my_uc_model"
| uc_migrated_copy = client.copy_model_version(src_model_uri, uc_model_dst_name)
| print_model_version_info(uc_migrated_copy)
|
| .. code-block:: text
| :caption: Output
|
| Name: RandomForestRegression-staging
| Version: 1
| Source: runs:/53e08bb38f0c487fa36c5872515ed998/sklearn-model
| --
| Name: RandomForestRegression-production
| Version: 1
| Source: models:/RandomForestRegression-staging/1
|
| create_dataset(self, name: str, experiment_id: str | list[str] | None = None, tags: dict[str, typing.Any] | None = None) -> mlflow.entities.evaluation_dataset.EvaluationDataset
| Create a new dataset.
|
| Args:
| name: The name of the dataset.
| experiment_id: Optional experiment ID (str) or list of experiment IDs to
| associate with the dataset.
| tags: Optional dictionary of tags to apply to the dataset.
|
| Returns:
| The created EvaluationDataset object.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Create a dataset associated with experiments
| dataset = client.create_dataset(
| name="qa_evaluation_v1",
| experiment_id=["0", "1"],
| tags={"environment": "production", "version": "1.0"},
| )
|
| create_experiment(self, name: str, artifact_location: str | None = None, tags: dict[str, typing.Any] | None = None) -> str
| Create an experiment.
|
| Args:
| name: The experiment name, which must be a unique string.
| artifact_location: The location to store run artifacts. If not provided, the server
| picks anappropriate default.
| tags: A dictionary of key-value pairs that are converted into
| :py:class:`mlflow.entities.ExperimentTag` objects, set as
| experiment tags upon experiment creation.
|
| Returns:
| String as an integer ID of the created experiment.
|
| .. code-block:: python
| :caption: Example
|
| from pathlib import Path
| from mlflow import MlflowClient
|
| # Create an experiment with a name that is unique and case sensitive.
| client = MlflowClient()
| experiment_id = client.create_experiment(
| "Social NLP Experiments",
| artifact_location=Path.cwd().joinpath("mlruns").as_uri(),
| tags={"version": "v1", "priority": "P1"},
| )
| client.set_experiment_tag(experiment_id, "nlp.framework", "Spark NLP")
|
| # Fetch experiment metadata information
| experiment = client.get_experiment(experiment_id)
| print(f"Name: {experiment.name}")
| print(f"Experiment_id: {experiment.experiment_id}")
| print(f"Artifact Location: {experiment.artifact_location}")
| print(f"Tags: {experiment.tags}")
| print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
|
| .. code-block:: text
| :caption: Output
|
| Name: Social NLP Experiments
| Experiment_id: 1
| Artifact Location: file:///.../mlruns
| Tags: {'version': 'v1', 'priority': 'P1', 'nlp.framework': 'Spark NLP'}
| Lifecycle_stage: active
|
| create_logged_model(self, experiment_id: str, name: str | None = None, source_run_id: str | None = None, tags: dict[str, str] | None = None, params: dict[str, str] | None = None, model_type: str | None = None) -> mlflow.entities.logged_model.LoggedModel
| Create a new logged model.
|
| Args:
| experiment_id: ID of the experiment to which the model belongs.
| name: Name of the model. If not specified, a random name will be generated.
| source_run_id: ID of the run that produced the model.
| tags: Tags to set on the model.
| params: Parameters to set on the model.
| model_type: The type of the model. This is a user-defined string that can be used to
| search and compare related models. For example, setting
| ``model_type="agent"`` enables you to easily search for this model and
| compare it to other models of type ``"agent"`` in the future.
|
| Returns:
| The created model.
|
| create_mcp_access_endpoint(self, server_name: str, url: str, transport_type: mlflow.entities.mcp_server.MCPRemoteTransportType = <MCPRemoteTransportType.STREAMABLE_HTTP: 'streamable-http'>, server_version: str | None = None, server_alias: str | None = None) -> mlflow.entities.mcp_access_endpoint.MCPAccessEndpoint
|
| create_mcp_server(self, name: str, description: str | None = None, icons: list[mlflow.store.tracking.mcp_server_registry.abstract_mixin.MCPIcon] | None = None) -> mlflow.entities.mcp_server.MCPServer
|
| create_mcp_server_version(self, server_json: dict[str, typing.Any], source: str | None = None, status: mlflow.entities.mcp_server.MCPStatus | None = None, tools: list[mlflow.entities.mcp_server.MCPTool] | None = <object object at 0x0000025F348EA210>, connect_options: dict[str, mlflow.entities.mcp_server_version.ConnectOptionSettings] | None = None) -> mlflow.entities.mcp_server_version.MCPServerVersion
|
| create_model_version(self, name: str, source: str, run_id: str | None = None, tags: dict[str, typing.Any] | None = None, run_link: str | None = None, description: str | None = None, await_creation_for: int = 300, model_id: str | None = None) -> mlflow.entities.model_registry.model_version.ModelVersion
| Create a new model version from given source.
|
| Args:
| name: Name for the containing registered model.
| source: URI indicating the location of the model artifacts. The artifact URI can be
| run relative (e.g. ``runs:/<run_id>/<model_artifact_path>``), a model
| registry URI (e.g. ``models:/<model_name>/<version>``), or other URIs
| supported by the model registry backend (e.g. `"s3://my_bucket/my/model"`).
| run_id: Run ID from MLflow tracking server that generated the model.
| tags: A dictionary of key-value pairs that are converted into
| :py:class:`mlflow.entities.model_registry.ModelVersionTag` objects.
| run_link: Link to the run from an MLflow tracking server that generated this model.
| description: Description of the version.
| await_creation_for: Number of seconds to wait for the model version to finish being
| created and is in ``READY`` status. By default, the function
| waits for five minutes. Specify 0 or None to skip waiting.
| model_id: The ID of the model (from an Experiment) that is being promoted to a
| registered model version, if applicable.
|
| Returns:
| Single :py:class:`mlflow.entities.model_registry.ModelVersion` object created by
| backend.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow.store.artifact.runs_artifact_repo import RunsArtifactRepository
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a new version of the rfr model under the registered model name
| desc = "A new version of the model"
| runs_uri = f"runs:/{run.info.run_id}/sklearn-model"
| model_src = RunsArtifactRepository.get_underlying_uri(runs_uri)
| mv = client.create_model_version(name, model_src, run.info.run_id, description=desc)
| print(f"Name: {mv.name}")
| print(f"Version: {mv.version}")
| print(f"Description: {mv.description}")
| print(f"Status: {mv.status}")
| print(f"Stage: {mv.current_stage}")
|
| .. code-block:: text
| :caption: Output
|
| Name: RandomForestRegression
| Version: 1
| Description: A new version of the model
| Status: READY
| Stage: None
|
| create_prompt(self, name: str, description: str | None = None, tags: dict[str, str] | None = None) -> mlflow.entities.model_registry.prompt.Prompt
| Create a new prompt in the registry.
|
| This method delegates directly to the store, providing full Unity Catalog support
| when used with Unity Catalog registries.
|
| Args:
| name: Name of the prompt.
| description: Optional description of the prompt.
| tags: Optional dictionary of prompt tags.
|
| Returns:
| A Prompt object.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| prompt_info = client.create_prompt(
| name="my_prompt",
| description="A helpful prompt",
| tags={"team": "data-science"},
| )
|
| create_prompt_version(self, name: str, template: str | list[dict[str, typing.Any]], description: str | None = None, tags: dict[str, str] | None = None, response_format: type[pydantic.main.BaseModel] | dict[str, typing.Any] | None = None, model_config: 'PromptModelConfig | dict[str, Any] | None' = None) -> mlflow.entities.model_registry.prompt_version.PromptVersion
| Create a new version of an existing prompt.
|
| This method delegates directly to the store, providing full Unity Catalog support
| when used with Unity Catalog registries.
|
| Args:
| name: Name of the prompt.
| template: The prompt template content for this version.
| description: Optional description of the prompt version.
| tags: Optional dictionary of prompt version tags.
| response_format: Optional Pydantic class or dictionary defining the expected response
| structure. This can be used to specify the schema for structured
| outputs from LLM calls.
| model_config: Optional PromptModelConfig object or dictionary defining the model
| configuration (model name, parameters, etc.) to use when invoking this
| prompt version.
|
| Returns:
| A PromptVersion object.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| prompt_version = client.create_prompt_version(
| name="my_prompt",
| template="Respond as a {{style}} assistant: {{query}}",
| description="Added style parameter",
| tags={"author": "alice"},
| )
|
| create_registered_model(self, name: str, tags: dict[str, typing.Any] | None = None, description: str | None = None, deployment_job_id: str | None = None) -> mlflow.entities.model_registry.registered_model.RegisteredModel
| Create a new registered model in backend store.
|
| Args:
| name: Name of the new model. This is expected to be unique in the backend store.
| tags: A dictionary of key-value pairs that are converted into
| :py:class:`mlflow.entities.model_registry.RegisteredModelTag` objects.
| description: Description of the model.
| deployment_job_id: Optional deployment job ID.
|
| Returns:
| A single object of :py:class:`mlflow.entities.model_registry.RegisteredModel`
| created by backend.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
|
| def print_registered_model_info(rm):
| print(f"name: {rm.name}")
| print(f"tags: {rm.tags}")
| print(f"description: {rm.description}")
|
|
| name = "SocialMediaTextAnalyzer"
| tags = {"nlp.framework": "Spark NLP"}
| desc = "This sentiment analysis model classifies the tone-happy, sad, angry."
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| client = MlflowClient()
| client.create_registered_model(name, tags, desc)
| print_registered_model_info(client.get_registered_model(name))
|
| .. code-block:: text
| :caption: Output
|
| name: SocialMediaTextAnalyzer
| tags: {'nlp.framework': 'Spark NLP'}
| description: This sentiment analysis model classifies the tone-happy, sad, angry.
|
| create_run(self, experiment_id: str, start_time: int | None = None, tags: dict[str, typing.Any] | None = None, run_name: str | None = None) -> mlflow.entities.run.Run
| Create a :py:class:`mlflow.entities.Run` object that can be associated with
| metrics, parameters, artifacts, etc.
| Unlike :py:func:`mlflow.projects.run`, creates objects but does not run code.
| Unlike :py:func:`mlflow.start_run`, does not change the "active run" used by
| :py:func:`mlflow.log_param`.
|
| Args:
| experiment_id: The string ID of the experiment to create a run in.
| start_time: If not provided, use the current timestamp.
| tags: A dictionary of key-value pairs that are converted into
| :py:class:`mlflow.entities.RunTag` objects.
| run_name: The name of this run.
|
| Returns:
| :py:class:`mlflow.entities.Run` that was created.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| # Create a run with a tag under the default experiment (whose id is '0').
| tags = {"engineering": "ML Platform"}
| name = "platform-run-24"
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id, tags=tags, run_name=name)
|
| # Show newly created run metadata info
| print(f"Run tags: {run.data.tags}")
| print(f"Experiment id: {run.info.experiment_id}")
| print(f"Run id: {run.info.run_id}")
| print(f"Run name: {run.info.run_name}")
| print(f"lifecycle_stage: {run.info.lifecycle_stage}")
| print(f"status: {run.info.status}")
|
| .. code-block:: text
| :caption: Output
|
| Run tags: {'engineering': 'ML Platform'}
| Experiment id: 0
| Run id: 65fb9e2198764354bab398105f2e70c1
| Run name: platform-run-24
| lifecycle_stage: active
| status: RUNNING
|
| create_webhook(self, name: str, url: str, events: list[typing.Union[typing.Literal['registered_model.created', 'model_version.created', 'model_version_tag.set', 'model_version_tag.deleted', 'model_version_alias.created', 'model_version_alias.deleted', 'prompt.created', 'prompt_version.created', 'prompt_tag.set', 'prompt_tag.deleted', 'prompt_version_tag.set', 'prompt_version_tag.deleted', 'prompt_alias.created', 'prompt_alias.deleted', 'budget_policy.exceeded'], mlflow.entities.webhook.WebhookEvent]], description: str | None = None, secret: str | None = None, status: str | mlflow.entities.webhook.WebhookStatus | None = None) -> mlflow.entities.webhook.Webhook
| Create a new webhook.
|
| Args:
| name: Name for the webhook.
| url: Webhook endpoint URL.
| events: List of events that trigger this webhook. Can be strings or
| `WebhookEvent` objects.
| description: Optional description of the webhook.
| secret: Optional secret for HMAC signature verification.
| status: Webhook status (defaults to ACTIVE). Can be string or WebhookStatus enum.
| Valid statuses: "ACTIVE", "DISABLED"
|
| Returns:
| A :py:class:`mlflow.entities.webhook.Webhook` object representing the created webhook.
|
| create_workspace(self, name: str, description: str | None = None, default_artifact_root: str | None = None, trace_archival_config: mlflow.entities.workspace.TraceArchivalConfig | None = None) -> mlflow.entities.workspace.Workspace
| Create a new workspace.
|
| Args:
| name: The workspace name (alphanumeric, hyphens, underscores only).
| description: Optional description of the workspace.
| default_artifact_root: Optional artifact root URI; falls back to server default.
| trace_archival_config: Optional Python-side grouping for trace archival settings.
| Use ``TraceArchivalConfig.location`` to set the archival storage URI/root and
| ``TraceArchivalConfig.retention`` to set the archived-trace retention duration such
| as ``30d`` or ``12h``. Leave fields as ``None`` to omit them from the create
| request.
|
| Returns:
| The newly created workspace.
|
| delete_dataset(self, dataset_id: str) -> None
| Delete a dataset and all its records.
|
| Args:
| dataset_id: The ID of the dataset to delete.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Delete a dataset
| client.delete_dataset("dataset_123")
|
| delete_dataset_tag(self, dataset_id: str, key: str) -> None
| Delete a tag from a dataset.
|
| Args:
| dataset_id: The ID of the dataset.
| key: The tag key to delete.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Delete a tag
| client.delete_dataset_tag(dataset_id="dataset123", key="deprecated")
|
| delete_experiment(self, experiment_id: str) -> None
| Delete an experiment from the backend store.
|
| This deletion is a soft-delete, not a permanent deletion. Experiment names can not be
| reused, unless the deleted experiment is permanently deleted by a database admin.
|
| Args:
| experiment_id: The experiment ID returned from ``create_experiment``.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| # Create an experiment with a name that is unique and case sensitive
| client = MlflowClient()
| experiment_id = client.create_experiment("New Experiment")
| client.delete_experiment(experiment_id)
|
| # Examine the deleted experiment details.
| experiment = client.get_experiment(experiment_id)
| print(f"Name: {experiment.name}")
| print(f"Artifact Location: {experiment.artifact_location}")
| print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
|
| .. code-block:: text
| :caption: Output
|
| Name: New Experiment
| Artifact Location: file:///.../mlruns/1
| Lifecycle_stage: deleted
|
| delete_experiment_tag(self, experiment_id: str, key: str) -> None
| Delete a tag from the experiment with the specified ID.
|
| Args:
| experiment_id: String ID of the experiment.
| key: Name of the tag to be deleted.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| # Create an experiment and set its tag
| client = MlflowClient()
| experiment_id = client.create_experiment("Social Media NLP Experiments")
| client.set_experiment_tag(experiment_id, "nlp.framework", "Spark NLP")
|
| # Fetch experiment metadata information, validate that tag is set
| experiment = client.get_experiment(experiment_id)
| assert experiment.tags == {"nlp.framework": "Spark NLP"}
|
| client.delete_experiment_tag(experiment_id, "nlp.framework")
|
| # Fetch experiment metadata information, validate that tag is deleted
| experiment = client.get_experiment(experiment_id)
| assert experiment.tags == {}
|
| delete_logged_model(self, model_id: str) -> None
| Delete the logged model with the specified ID.
|
| Args:
| model_id: ID of the model to delete.
|
| delete_logged_model_tag(self, model_id: str, key: str) -> None
| Delete a tag from the specified logged model.
|
| Args:
| model_id: ID of the model.
| key: Tag key to delete.
|
| delete_mcp_access_endpoint(self, server_name: str, endpoint_id: str) -> None
|
| delete_mcp_server(self, name: str) -> None
|
| delete_mcp_server_alias(self, name: str, alias: str) -> None
|
| delete_mcp_server_tag(self, name: str, key: str) -> None
|
| delete_mcp_server_version(self, name: str, version: str) -> None
|
| delete_mcp_server_version_tag(self, name: str, version: str, key: str) -> None
|
| delete_model_version(self, name: str, version: str) -> None
| Delete model version in backend.
|
| Args:
| name: Name of the containing registered model.
| version: Version number of the model version.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_models_info(mv):
| for m in mv:
| print(f"name: {m.name}")
| print(f"latest version: {m.version}")
| print(f"run_id: {m.run_id}")
| print(f"current_stage: {m.current_stage}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
|
| # Create two runs and log MLflow entities
| with mlflow.start_run() as run1:
| params = {"n_estimators": 3, "random_state": 42}
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| with mlflow.start_run() as run2:
| params = {"n_estimators": 6, "random_state": 42}
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| name = "RandomForestRegression"
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a two versions of the rfr model under the registered model name
| for run_id in [run1.info.run_id, run2.info.run_id]:
| model_uri = f"runs:/{run_id}/sklearn-model"
| mv = client.create_model_version(name, model_uri, run_id)
| print(f"model version {mv.version} created")
|
| print("--")
|
| # Fetch latest version; this will be version 2
| models = client.get_latest_versions(name, stages=["None"])
| print_models_info(models)
| print("--")
|
| # Delete the latest model version 2
| print(f"Deleting model version {mv.version}")
| client.delete_model_version(name, mv.version)
| models = client.get_latest_versions(name, stages=["None"])
| print_models_info(models)
|
| .. code-block:: text
| :caption: Output
|
| model version 1 created
| model version 2 created
| --
| name: RandomForestRegression
| latest version: 2
| run_id: 9881172ef10f4cb08df3ed452c0c362b
| current_stage: None
| --
| Deleting model version 2
| name: RandomForestRegression
| latest version: 1
| run_id: 9165d4f8aa0a4d069550824bdc55caaf
| current_stage: None
|
| delete_model_version_tag(self, name: str, version: str | None = None, key: str | None = None, stage: str | None = None) -> None
| Delete a tag associated with the model version.
|
| When stage is set, tag will be deleted for latest model version of the stage.
| Setting both version and stage parameter will result in error.
|
| Args:
| name: Registered model name.
| version: Registered model version.
| key: Tag key. key is required.
| stage: Registered model stage.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_version_info(mv):
| print(f"Name: {mv.name}")
| print(f"Version: {mv.version}")
| print(f"Tags: {mv.tags}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a new version of the rfr model under the registered model name
| # and delete a tag
| model_uri = f"runs:/{run.info.run_id}/sklearn-model"
| tags = {"t": "1", "t1": "2"}
| mv = client.create_model_version(name, model_uri, run.info.run_id, tags=tags)
| print_model_version_info(mv)
| print("--")
| # using version to delete tag
| client.delete_model_version_tag(name, mv.version, "t")
|
| # using stage to delete tag
| client.delete_model_version_tag(name, key="t1", stage=mv.current_stage)
| mv = client.get_model_version(name, mv.version)
| print_model_version_info(mv)
|
| .. code-block:: text
| :caption: Output
|
| Name: RandomForestRegression
| Version: 1
| Tags: {'t': '1', 't1': '2'}
| --
| Name: RandomForestRegression
| Version: 1
| Tags: {}
|
| delete_prompt(self, name: str) -> None
| Delete a prompt from the registry.
|
| For Unity Catalog registries, this method first checks if any versions exist for the prompt
| and throws an error if undeleted versions are found. All versions must be explicitly
| deleted first before the prompt itself can be deleted.
|
| For other registries, the prompt is deleted normally without version checking.
|
| Args:
| name: Name of the prompt to delete.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # For Unity Catalog, delete all versions first
| if client.get_registry_uri().startswith("databricks-uc"):
| versions = client.search_prompt_versions("my_prompt")
| for version in versions:
| client.delete_prompt_version("my_prompt", version.version)
|
| # Then delete the prompt
| client.delete_prompt("my_prompt")
|
| delete_prompt_alias(self, name: str, alias: str) -> None
| Delete an alias for a :py:class:`Prompt <mlflow.entities.Prompt>`.
|
| Args:
| name: The name of the prompt.
| alias: The alias to delete for the prompt.
|
| delete_prompt_tag(self, name: str, key: str) -> None
| Delete a tag from a prompt.
|
| This method delegates directly to the store, providing full Unity Catalog support
| when used with Unity Catalog registries.
|
| Args:
| name: Name of the prompt.
| key: Tag key to delete.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| client.delete_prompt_tag("my_prompt", "environment")
|
| delete_prompt_version(self, name: str, version: str) -> None
| Delete a specific prompt version.
|
| This method delegates directly to the store, providing full Unity Catalog support
| when used with Unity Catalog registries.
|
| Args:
| name: Name of the prompt.
| version: Version of the prompt to delete.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| client.delete_prompt_version("my_prompt", "1")
|
| delete_prompt_version_tag(self, name: str, version: str | int, key: str) -> None
| Delete a tag from a specific prompt version.
|
| Args:
| name: The name of the prompt.
| version: The version number of the prompt.
| key: The tag key to delete.
|
| delete_registered_model(self, name: str)
| Delete registered model.
| Backend raises exception if a registered model with given name does not exist.
|
| Args:
| name: Name of the registered model to delete.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
|
| def print_registered_models_info(r_models):
| print("--")
| for rm in r_models:
| print(f"name: {rm.name}")
| print(f"tags: {rm.tags}")
| print(f"description: {rm.description}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| client = MlflowClient()
|
| # Register a couple of models with respective names, tags, and descriptions
| for name, tags, desc in [
| ("name1", {"t1": "t1"}, "description1"),
| ("name2", {"t2": "t2"}, "description2"),
| ]:
| client.create_registered_model(name, tags, desc)
|
| # Fetch all registered models
| print_registered_models_info(client.search_registered_models())
|
| # Delete one registered model and fetch again
| client.delete_registered_model("name1")
| print_registered_models_info(client.search_registered_models())
|
| .. code-block:: text
| :caption: Output
|
| --
| name: name1
| tags: {'t1': 't1'}
| description: description1
| name: name2
| tags: {'t2': 't2'}
| description: description2
| --
| name: name2
| tags: {'t2': 't2'}
| description: description2
|
| delete_registered_model_alias(self, name: str, alias: str) -> None
| Delete an alias associated with a registered model.
|
| Args:
| name: Registered model name.
| alias: Name of the alias.
|
| .. code-block:: Python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_info(rm):
| print("--Model--")
| print("name: {}".format(rm.name))
| print("aliases: {}".format(rm.aliases))
|
|
| def print_model_version_info(mv):
| print("--Model Version--")
| print("Name: {}".format(mv.name))
| print("Version: {}".format(mv.version))
| print("Aliases: {}".format(mv.aliases))
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, artifact_path="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
| model = client.get_registered_model(name)
| print_model_info(model)
|
| # Create a new version of the rfr model under the registered model name
| model_uri = "runs:/{}/sklearn-model".format(run.info.run_id)
| mv = client.create_model_version(name, model_uri, run.info.run_id)
| print_model_version_info(mv)
|
| # Set registered model alias
| client.set_registered_model_alias(name, "test-alias", mv.version)
| print()
| print_model_info(model)
| print_model_version_info(mv)
|
| # Delete registered model alias
| client.delete_registered_model_alias(name, "test-alias")
| print()
| print_model_info(model)
| print_model_version_info(mv)
|
| .. code-block:: text
| :caption: Output
|
| --Model--
| name: RandomForestRegression
| aliases: {}
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: []
|
| --Model--
| name: RandomForestRegression
| aliases: {"test-alias": "1"}
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: ["test-alias"]
|
| --Model--
| name: RandomForestRegression
| aliases: {}
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: []
|
| delete_registered_model_tag(self, name: str, key: str) -> None
| Delete a tag associated with the registered model.
|
| Args:
| name: Registered model name.
| key: Registered model tag key.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
|
| def print_registered_models_info(r_models):
| print("--")
| for rm in r_models:
| print(f"name: {rm.name}")
| print(f"tags: {rm.tags}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| client = MlflowClient()
|
| # Register a couple of models with respective names and tags
| for name, tags in [("name1", {"t1": "t1"}), ("name2", {"t2": "t2"})]:
| client.create_registered_model(name, tags)
|
| # Fetch all registered models
| print_registered_models_info(client.search_registered_models())
| # Delete a tag from model `name2`
| client.delete_registered_model_tag("name2", "t2")
| print_registered_models_info(client.search_registered_models())
|
| .. code-block:: text
| :caption: Output
|
| --
| name: name1
| tags: {'t1': 't1'}
| name: name2
| tags: {'t2': 't2'}
| --
| name: name1
| tags: {'t1': 't1'}
| name: name2
| tags: {}
|
| delete_run(self, run_id: str) -> None
| Deletes a run with the given ID.
|
| Args:
| run_id: The unique run id to delete.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| # Create a run under the default experiment (whose id is '0').
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| run_id = run.info.run_id
| print(f"run_id: {run_id}; lifecycle_stage: {run.info.lifecycle_stage}")
| print("--")
| client.delete_run(run_id)
| del_run = client.get_run(run_id)
| print(f"run_id: {run_id}; lifecycle_stage: {del_run.info.lifecycle_stage}")
|
| .. code-block:: text
| :caption: Output
|
| run_id: a61c7a1851324f7094e8d5014c58c8c8; lifecycle_stage: active
| run_id: a61c7a1851324f7094e8d5014c58c8c8; lifecycle_stage: deleted
|
| delete_tag(self, run_id: str, key: str) -> None
| Delete a tag from a run. This is irreversible.
|
| Args:
| run_id: String ID of the run.
| key: Name of the tag.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_run_info(run):
| print(f"run_id: {run.info.run_id}")
| print(f"Tags: {run.data.tags}")
|
|
| # Create a run under the default experiment (whose id is '0').
| client = MlflowClient()
| tags = {"t1": 1, "t2": 2}
| experiment_id = "0"
| run = client.create_run(experiment_id, tags=tags)
| print_run_info(run)
| print("--")
|
| # Delete tag and fetch updated info
| client.delete_tag(run.info.run_id, "t1")
| run = client.get_run(run.info.run_id)
| print_run_info(run)
|
| .. code-block:: text
| :caption: Output
|
| run_id: b7077267a59a45d78cd9be0de4bc41f5
| Tags: {'t2': '2', 't1': '1'}
| --
| run_id: b7077267a59a45d78cd9be0de4bc41f5
| Tags: {'t2': '2'}
|
| delete_trace_tag(self, trace_id: str, key: str) -> None
| .. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
|
| Delete a tag on the trace with the given trace ID.
|
| The trace can be an active one or the one that has already ended and recorded in the
| backend. Below is an example of deleting a tag on an active trace. You can replace the
| ``trace_id`` parameter to delete a tag on an already ended trace.
|
| .. code-block:: python
| :test:
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| root_span = client.start_trace("my_trace", tags={"key": "value"})
| client.delete_trace_tag(root_span.trace_id, "key")
| client.end_trace(root_span.trace_id)
|
| Args:
| trace_id: The ID of the trace to delete the tag from.
| key: The string key of the tag. Must be at most 250 characters long, otherwise
| it will be truncated when stored.
|
| delete_traces(self, experiment_id: str, max_timestamp_millis: int | None = None, max_traces: int | None = None, trace_ids: list[str] | None = None) -> int
| Delete traces based on the specified criteria.
|
| - Either `max_timestamp_millis` or `trace_ids` must be specified, but not both.
| - `max_traces` can't be specified if `trace_ids` is specified.
|
| Args:
| experiment_id: ID of the associated experiment.
| max_timestamp_millis: The maximum timestamp in milliseconds since the UNIX epoch for
| deleting traces. Traces older than or equal to this timestamp will be deleted.
| max_traces: The maximum number of traces to delete. If max_traces is specified, and
| it is less than the number of traces that would be deleted based on the
| max_timestamp_millis, the oldest traces will be deleted first.
| trace_ids: A set of trace IDs to delete.
|
| Returns:
| The number of traces deleted.
|
| Example:
|
| .. code-block:: python
| :test:
|
| import mlflow
| import time
|
| client = mlflow.MlflowClient()
|
| # Delete all traces in the experiment
| client.delete_traces(
| experiment_id="0", max_timestamp_millis=time.time_ns() // 1_000_000
| )
|
| # Delete traces based on max_timestamp_millis and max_traces
| # Older traces will be deleted first.
| some_timestamp = time.time_ns() // 1_000_000
| client.delete_traces(
| experiment_id="0", max_timestamp_millis=some_timestamp, max_traces=2
| )
|
| # Delete traces based on trace_ids
| client.delete_traces(experiment_id="0", trace_ids=["id_1", "id_2"])
|
| delete_webhook(self, webhook_id: str) -> None
| Delete a webhook.
|
| Args:
| webhook_id: Webhook ID to delete.
|
| Returns:
| None
|
| delete_workspace(self, name: str, mode: str = <WorkspaceDeletionMode.RESTRICT: 'RESTRICT'>) -> None
| Delete an existing workspace.
|
| Args:
| name: Name of the workspace to delete.
| mode: Deletion mode — ``"SET_DEFAULT"``, ``"CASCADE"``, or ``"RESTRICT"``.
|
| detach_prompt_from_run(self, run_id: str, prompt_uri: str) -> None
| Detach a prompt registered within the MLflow Prompt Registry from an MLflow Run.
|
| Args:
| run_id: The ID of the run to log the prompt to.
| prompt_uri: The prompt URI in the format "prompts:/name/version".
|
| download_artifacts(self, run_id: str, path: str, dst_path: str | None = None) -> str
| Download an artifact file or directory from a run to a local directory if applicable,
| and return a local path for it.
|
| Args:
| run_id: The run to download artifacts from.
| path: Relative source path to the desired artifact.
| dst_path: Absolute path of the local filesystem destination directory to which to
| download the specified artifacts. This directory must already exist.
| If unspecified, the artifacts will either be downloaded to a new
| uniquely-named directory on the local filesystem or will be returned
| directly in the case of the LocalArtifactRepository.
|
| Returns:
| Local path of desired artifact.
|
| .. code-block:: python
| :caption: Example
|
| import os
| import mlflow
| from mlflow import MlflowClient
|
| features = "rooms, zipcode, median_price, school_rating, transport"
| with open("features.txt", "w") as f:
| f.write(features)
|
| # Log artifacts
| with mlflow.start_run() as run:
| mlflow.log_artifact("features.txt", artifact_path="features")
|
| # Download artifacts
| client = MlflowClient()
| local_dir = "/tmp/artifact_downloads"
| if not os.path.exists(local_dir):
| os.mkdir(local_dir)
| local_path = client.download_artifacts(run.info.run_id, "features", local_dir)
| print(f"Artifacts downloaded in: {local_path}")
| print(f"Artifacts: {os.listdir(local_path)}")
|
| .. code-block:: text
| :caption: Output
|
| Artifacts downloaded in: /tmp/artifact_downloads/features
| Artifacts: ['features.txt']
|
| end_span(self, trace_id: str, span_id: str, outputs: typing.Any | None = None, attributes: dict[str, typing.Any] | None = None, status: mlflow.entities.span_status.SpanStatus | str = 'OK', end_time_ns: int | None = None)
| .. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
|
| End the span with the given trace ID and span ID.
|
| Args:
| trace_id: The ID of the trace to end.
| span_id: The ID of the span to end.
| outputs: Outputs to set on the span.
| attributes: A dictionary of attributes to set on the span. If the span already has
| attributes, the new attributes will be merged with the existing ones. If the same
| key already exists, the new value will overwrite the old one.
| status: The status of the span. This can be a
| :py:class:`SpanStatus <mlflow.entities.SpanStatus>` object or a string
| representing the status code defined in
| :py:class:`SpanStatusCode <mlflow.entities.SpanStatusCode>`
| e.g. ``"OK"``, ``"ERROR"``. The default status is OK.
| end_time_ns: The end time of the span in nano seconds since the UNIX epoch.
| If not provided, the current time will be used.
|
| end_trace(self, trace_id: str, outputs: typing.Any | None = None, attributes: dict[str, typing.Any] | None = None, status: mlflow.entities.span_status.SpanStatus | str = 'OK', end_time_ns: int | None = None)
| .. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
|
| End the trace with the given trace ID. This will end the root span of the trace and
| log the trace to the backend if configured.
|
| If any of children spans are not ended, they will be ended forcefully with the status
| ``TRACE_STATUS_UNSPECIFIED``. If the trace is already ended, this method will have
| no effect.
|
| Args:
| trace_id: The ID of the trace to end.
| outputs: Outputs to set on the trace.
| attributes: A dictionary of attributes to set on the trace. If the trace already
| has attributes, the new attributes will be merged with the existing ones.
| If the same key already exists, the new value will overwrite the old one.
| status: The status of the trace. This can be a
| :py:class:`SpanStatus <mlflow.entities.SpanStatus>` object or a string
| representing the status code defined in
| :py:class:`SpanStatusCode <mlflow.entities.SpanStatusCode>`
| e.g. ``"OK"``, ``"ERROR"``. The default status is OK.
| end_time_ns: The end time of the trace in nanoseconds since the UNIX epoch.
|
| finalize_logged_model(self, model_id: str, status: Union[Literal['READY', 'FAILED'], mlflow.entities.logged_model_status.LoggedModelStatus]) -> mlflow.entities.logged_model.LoggedModel
| Finalize a model by updating its status.
|
| Args:
| model_id: ID of the model to finalize.
| status: Final status to set on the model.
|
| Returns:
| The updated model.
|
| get_dataset(self, dataset_id: str) -> mlflow.entities.evaluation_dataset.EvaluationDataset
| Get a dataset by ID.
|
| Args:
| dataset_id: The ID of the dataset to retrieve.
|
| Returns:
| The EvaluationDataset object.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Get a dataset by ID (assuming it exists)
| dataset = client.get_dataset("dataset_123")
|
| # Access records (lazy loaded)
| df = dataset.to_df()
|
| get_experiment(self, experiment_id: str) -> mlflow.entities.experiment.Experiment
| Retrieve an experiment by experiment_id from the backend store
|
| Args:
| experiment_id: The experiment ID returned from ``create_experiment``.
|
| Returns:
| :py:class:`mlflow.entities.Experiment`
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| exp_id = client.create_experiment("Experiment")
| experiment = client.get_experiment(exp_id)
|
| # Show experiment info
| print(f"Name: {experiment.name}")
| print(f"Experiment ID: {experiment.experiment_id}")
| print(f"Artifact Location: {experiment.artifact_location}")
| print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
|
| .. code-block:: text
| :caption: Output
|
| Name: Experiment
| Experiment ID: 1
| Artifact Location: file:///.../mlruns/1
| Lifecycle_stage: active
|
| get_experiment_by_name(self, name: str) -> mlflow.entities.experiment.Experiment | None
| Retrieve an experiment by experiment name from the backend store
|
| Args:
| name: The experiment name, which is case sensitive.
|
| Returns:
| An instance of :py:class:`mlflow.entities.Experiment`
| if an experiment with the specified name exists, otherwise None.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| # Case-sensitive name
| client = MlflowClient()
| experiment = client.get_experiment_by_name("Default")
| # Show experiment info
| print(f"Name: {experiment.name}")
| print(f"Experiment ID: {experiment.experiment_id}")
| print(f"Artifact Location: {experiment.artifact_location}")
| print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
|
| .. code-block:: text
| :caption: Output
|
| Name: Default
| Experiment ID: 0
| Artifact Location: file:///.../mlruns/0
| Lifecycle_stage: active
|
| get_latest_mcp_server_version(self, name: str) -> mlflow.entities.mcp_server_version.MCPServerVersion
|
| get_latest_versions(self, name: str, stages: list[str] | None = None) -> list[mlflow.entities.model_registry.model_version.ModelVersion]
| .. Warning:: ``mlflow.tracking.client.MlflowClient.get_latest_versions`` is deprecated since 2.9.0. Model registry stages will be removed in a future major release. To learn more about the deprecation of model registry stages, see our migration guide here: https://mlflow.org/docs/latest/model-registry.html#migrating-from-stages
|
| Latest version models for each requests stage. If no ``stages`` provided, returns the
| latest version for each stage.
|
| Args:
| name: Name of the registered model from which to get the latest versions.
| stages: List of desired stages. If input list is None, return latest versions for
| for ALL_STAGES.
|
| Returns:
| List of :py:class:`mlflow.entities.model_registry.ModelVersion` objects.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_models_info(mv):
| for m in mv:
| print(f"name: {m.name}")
| print(f"latest version: {m.version}")
| print(f"run_id: {m.run_id}")
| print(f"current_stage: {m.current_stage}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| # Create two runs Log MLflow entities
| with mlflow.start_run() as run1:
| params = {"n_estimators": 3, "random_state": 42}
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
| with mlflow.start_run() as run2:
| params = {"n_estimators": 6, "random_state": 42}
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
| # Register model name in the model registry
| name = "RandomForestRegression"
| client = MlflowClient()
| client.create_registered_model(name)
| # Create a two versions of the rfr model under the registered model name
| for run_id in [run1.info.run_id, run2.info.run_id]:
| model_uri = f"runs:/{run_id}/sklearn-model"
| mv = client.create_model_version(name, model_uri, run_id)
| print(f"model version {mv.version} created")
| # Fetch latest version; this will be version 2
| print("--")
| print_models_info(client.get_latest_versions(name, stages=["None"]))
|
| .. code-block:: text
| :caption: Output
|
| model version 1 created
| model version 2 created
| --
| name: RandomForestRegression
| latest version: 2
| run_id: 31165664be034dc698c52a4bdeb71663
| current_stage: None
|
| get_logged_model(self, model_id: str) -> mlflow.entities.logged_model.LoggedModel
| Fetch the logged model with the specified ID.
|
| Args:
| model_id: ID of the model to fetch.
|
| Returns:
| The fetched model.
|
| get_mcp_access_endpoint(self, server_name: str, endpoint_id: str) -> mlflow.entities.mcp_access_endpoint.MCPAccessEndpoint
|
| get_mcp_server(self, name: str) -> mlflow.entities.mcp_server.MCPServer
|
| get_mcp_server_version(self, name: str, version: str) -> mlflow.entities.mcp_server_version.MCPServerVersion
|
| get_mcp_server_version_by_alias(self, name: str, alias: str) -> mlflow.entities.mcp_server_version.MCPServerVersion
|
| get_metric_history(self, run_id: str, key: str) -> list[mlflow.entities.metric.Metric]
| Return a list of metric objects corresponding to all values logged for a given metric.
|
| Args:
| run_id: Unique identifier for run.
| key: Metric name within the run.
|
| Returns:
| A list of :py:class:`mlflow.entities.Metric` entities if logged, else empty list.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_metric_info(history):
| for m in history:
| print(f"name: {m.key}")
| print(f"value: {m.value}")
| print(f"step: {m.step}")
| print(f"timestamp: {m.timestamp}")
| print("--")
|
|
| # Create a run under the default experiment (whose id is "0"). Since this is low-level
| # CRUD operation, the method will create a run. To end the run, you'll have
| # to explicitly end it.
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| print(f"run_id: {run.info.run_id}")
| print("--")
|
| # Log couple of metrics, update their initial value, and fetch each
| # logged metrics' history.
| for k, v in [("m1", 1.5), ("m2", 2.5)]:
| client.log_metric(run.info.run_id, k, v, step=0)
| client.log_metric(run.info.run_id, k, v + 1, step=1)
| print_metric_info(client.get_metric_history(run.info.run_id, k))
| client.set_terminated(run.info.run_id)
|
| .. code-block:: text
| :caption: Output
|
| run_id: c360d15714994c388b504fe09ea3c234
| --
| name: m1
| value: 1.5
| step: 0
| timestamp: 1603423788607
| --
| name: m1
| value: 2.5
| step: 1
| timestamp: 1603423788608
| --
| name: m2
| value: 2.5
| step: 0
| timestamp: 1603423788609
| --
| name: m2
| value: 3.5
| step: 1
| timestamp: 1603423788610
| --
|
| get_model_version(self, name: str, version: str) -> mlflow.entities.model_registry.model_version.ModelVersion
| Converts the docstring args and returns to google style.
|
| Args:
| name: Name of the containing registered model.
| version: Version number as an integer of the model version.
|
| Returns:
| A single :py:class:`mlflow.entities.model_registry.ModelVersion` object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
|
| # Create two runs Log MLflow entities
| with mlflow.start_run() as run1:
| params = {"n_estimators": 3, "random_state": 42}
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| with mlflow.start_run() as run2:
| params = {"n_estimators": 6, "random_state": 42}
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| name = "RandomForestRegression"
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a two versions of the rfr model under the registered model name
| for run_id in [run1.info.run_id, run2.info.run_id]:
| model_uri = f"runs:/{run_id}/sklearn-model"
| mv = client.create_model_version(name, model_uri, run_id)
| print(f"model version {mv.version} created")
| print("--")
|
| # Fetch the last version; this will be version 2
| mv = client.get_model_version(name, mv.version)
| print(f"Name: {mv.name}")
| print(f"Version: {mv.version}")
|
| .. code-block:: text
| :caption: Output
|
| model version 1 created
| model version 2 created
| --
| Name: RandomForestRegression
| Version: 2
|
| get_model_version_by_alias(self, name: str, alias: str) -> mlflow.entities.model_registry.model_version.ModelVersion
| Get the model version instance by name and alias.
|
| Args:
| name: Registered model name.
| alias: Name of the alias.
|
| Returns:
| A single :py:class:`mlflow.entities.model_registry.ModelVersion` object.
|
| .. code-block:: Python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_info(rm):
| print("--Model--")
| print("name: {}".format(rm.name))
| print("aliases: {}".format(rm.aliases))
|
|
| def print_model_version_info(mv):
| print("--Model Version--")
| print("Name: {}".format(mv.name))
| print("Version: {}".format(mv.version))
| print("Aliases: {}".format(mv.aliases))
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, artifact_path="sklearn-model", signature=signature)
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
| model = client.get_registered_model(name)
| print_model_info(model)
| # Create a new version of the rfr model under the registered model name
| model_uri = "runs:/{}/sklearn-model".format(run.info.run_id)
| mv = client.create_model_version(name, model_uri, run.info.run_id)
| print_model_version_info(mv)
| # Set registered model alias
| client.set_registered_model_alias(name, "test-alias", mv.version)
| print()
| print_model_info(model)
| print_model_version_info(mv)
| # Get model version by alias
| alias_mv = client.get_model_version_by_alias(name, "test-alias")
| print()
| print_model_version_info(alias_mv)
|
| .. code-block:: text
| :caption: Output
|
| --Model--
| name: RandomForestRegression
| aliases: {}
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: []
| --Model--
| name: RandomForestRegression
| aliases: {"test-alias": "1"}
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: ["test-alias"]
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: ["test-alias"]
|
| get_model_version_download_uri(self, name: str, version: str) -> str
| Get the download location in Model Registry for this model version.
|
| Args:
| name: Name of the containing registered model.
| version: Version number as an integer of the model version.
|
| Returns:
| A single URI location that allows reads for downloading.
|
| .. code-block:: python
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a new version of the rfr model under the registered model name
| model_uri = f"runs:/{run.info.run_id}/sklearn-model"
| mv = client.create_model_version(name, model_uri, run.info.run_id)
| artifact_uri = client.get_model_version_download_uri(name, mv.version)
| print(f"Download URI: {artifact_uri}")
|
| .. code-block:: text
|
| Download URI: runs:/027d7bbe81924c5a82b3e4ce979fcab7/sklearn-model
|
| get_model_version_stages(self, name: str, version: str) -> list[str]
| .. Warning:: ``mlflow.tracking.client.MlflowClient.get_model_version_stages`` is deprecated since 2.9.0. Model registry stages will be removed in a future major release. To learn more about the deprecation of model registry stages, see our migration guide here: https://mlflow.org/docs/latest/model-registry.html#migrating-from-stages
|
| This is a docstring. Here is info.
|
| Returns:
| A list of valid stages.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a new version of the rfr model under the registered model name
| # fetch valid stages
| model_uri = f"runs:/{run.info.run_id}/models/sklearn-model"
| mv = client.create_model_version(name, model_uri, run.info.run_id)
| stages = client.get_model_version_stages(name, mv.version)
| print(f"Model list of valid stages: {stages}")
|
| .. code-block:: text
| :caption: Output
|
| Model list of valid stages: ['None', 'Staging', 'Production', 'Archived']
|
| get_parent_run(self, run_id: str) -> mlflow.entities.run.Run | None
| Gets the parent run for the given run id if one exists.
|
| Args:
| run_id: Unique identifier for the child run.
|
| Returns:
| A single :py:class:`mlflow.entities.Run` object, if the parent run exists. Otherwise,
| returns None.
|
| .. code-block:: python
| :test:
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
| # Create nested runs
| with mlflow.start_run():
| with mlflow.start_run(nested=True) as child_run:
| child_run_id = child_run.info.run_id
|
| client = MlflowClient()
| parent_run = client.get_parent_run(child_run_id)
|
| print(f"child_run_id: {child_run_id}")
| print(f"parent_run_id: {parent_run.info.run_id}")
|
| .. code-block:: text
| :caption: Output
|
| child_run_id: 7d175204675e40328e46d9a6a5a7ee6a
| parent_run_id: 8979459433a24a52ab3be87a229a9cdf
|
| get_prompt(self, name: str) -> mlflow.entities.model_registry.prompt.Prompt | None
| Get prompt metadata by name.
|
| Args:
| name: Name of the prompt.
|
| Returns:
| A Prompt object containing prompt metadata, or None if not found.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| prompt = client.get_prompt("my_prompt")
| if prompt:
| print(f"Prompt: {prompt.name}")
| print(f"Description: {prompt.description}")
|
| get_prompt_version(self, name: str, version: str | int) -> mlflow.entities.model_registry.prompt_version.PromptVersion | None
| Get a specific prompt version.
|
| This method delegates directly to the store, providing full Unity Catalog support
| when used with Unity Catalog registries.
|
| Args:
| name: Name of the prompt.
| version: Version of the prompt (number or alias).
|
| Returns:
| A PromptVersion object with the specific version content, or None if not found.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| prompt_version = client.get_prompt_version("my_prompt", "1")
| prompt_alias = client.get_prompt_version("my_prompt", "production")
|
| get_prompt_version_by_alias(self, name: str, alias: str) -> mlflow.entities.model_registry.prompt_version.PromptVersion
| Get a prompt version by alias.
|
| This method delegates directly to the store, providing full Unity Catalog support
| when used with Unity Catalog registries.
|
| Args:
| name: Name of the prompt.
| alias: Alias of the prompt version.
|
| Returns:
| A PromptVersion object.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| prompt_version = client.get_prompt_version_by_alias("my_prompt", "production")
|
| get_registered_model(self, name: str) -> mlflow.entities.model_registry.registered_model.RegisteredModel
| Get a registered model.
|
| Args:
| name: Name of the registered model to get.
|
| Returns:
| A single :py:class:`mlflow.entities.model_registry.RegisteredModel` object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
|
| def print_model_info(rm):
| print("--")
| print(f"name: {rm.name}")
| print(f"tags: {rm.tags}")
| print(f"description: {rm.description}")
|
|
| name = "SocialMediaTextAnalyzer"
| tags = {"nlp.framework": "Spark NLP"}
| desc = "This sentiment analysis model classifies the tone-happy, sad, angry."
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| client = MlflowClient()
| # Create and fetch the registered model
| client.create_registered_model(name, tags, desc)
| model = client.get_registered_model(name)
| print_model_info(model)
|
| .. code-block:: text
| :caption: Output
|
| --
| name: SocialMediaTextAnalyzer
| tags: {'nlp.framework': 'Spark NLP'}
| description: This sentiment analysis model classifies the tone-happy, sad, angry.
|
| get_run(self, run_id: str) -> mlflow.entities.run.Run
| Fetch the run from backend store. The resulting :py:class:`Run <mlflow.entities.Run>`
| contains a collection of run metadata -- :py:class:`RunInfo <mlflow.entities.RunInfo>`,
| as well as a collection of run parameters, tags, and metrics --
| :py:class:`RunData <mlflow.entities.RunData>`. It also contains a collection of run
| inputs (experimental), including information about datasets used by the run --
| :py:class:`RunInputs <mlflow.entities.RunInputs>`. In the case where multiple metrics with
| the same key are logged for the run, the :py:class:`RunData <mlflow.entities.RunData>`
| contains the most recently logged value at the largest step for each metric.
|
| Args:
| run_id: Unique identifier for the run.
|
| Returns:
| A single :py:class:`mlflow.entities.Run` object, if the run exists. Otherwise,
| raises an exception.
|
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
| with mlflow.start_run() as run:
| mlflow.log_param("p", 0)
|
| # The run has finished since we have exited the with block
| # Fetch the run
| client = MlflowClient()
| run = client.get_run(run.info.run_id)
| print(f"run_id: {run.info.run_id}")
| print(f"params: {run.data.params}")
| print(f"status: {run.info.status}")
|
| .. code-block:: text
| :caption: Output
|
| run_id: e36b42c587a1413ead7c3b6764120618
| params: {'p': '0'}
| status: FINISHED
|
| get_trace(self, trace_id: str, display=True, flush: bool = False) -> mlflow.entities.trace.Trace
| .. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
|
| Get the trace matching the specified ``trace_id``.
|
| Args:
| trace_id: String ID of the trace to fetch.
| display: If ``True``, display the trace on the notebook.
| flush: If ``True``, flush any pending async trace writes before fetching.
| Useful in tests or scripts where async logging may not have completed.
| Default to ``False``.
|
| Returns:
| The retrieved :py:class:`Trace <mlflow.entities.Trace>`.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| trace_id = "12345678"
| trace = client.get_trace(trace_id)
|
| get_webhook(self, webhook_id: str) -> mlflow.entities.webhook.Webhook
| Get webhook instance by ID.
|
| Args:
| webhook_id: Webhook ID.
|
| Returns:
| A :py:class:`mlflow.entities.webhook.Webhook` object.
|
| get_workspace(self, name: str) -> mlflow.entities.workspace.Workspace
| Return metadata for the specified workspace.
|
| get_workspace_store_uri(self) -> str
| Return the resolved workspace provider URI. This value is always non-null because
| `resolve_workspace_store_uri()` falls back to the tracking URI when no workspace URI is
| explicitly provided.
|
| link_prompt_version_to_model(self, name: str, version: str, model_id: str) -> None
| Link a prompt version to a model.
|
| Args:
| name: The name of the prompt.
| version: The version of the prompt.
| model_id: The ID of the model to link the prompt version to.
|
| link_prompt_version_to_run(self, run_id: str, prompt: str | mlflow.entities.model_registry.prompt_version.PromptVersion) -> None
| Link a prompt registered within the MLflow Prompt Registry with an MLflow Run.
|
| .. warning::
|
| This API is not thread-safe. If you are linking prompts from multiple threads,
| consider using a lock to ensure that only one thread links a prompt to a run at a time.
|
| Args:
| run_id: The ID of the run to link the prompt to.
| prompt: A Prompt object or the prompt URI in the format "prompts:/name/version".
|
| link_prompt_versions_to_trace(self, prompt_versions: list[mlflow.entities.model_registry.prompt_version.PromptVersion], trace_id: str) -> None
| Link multiple prompt versions to a trace.
|
| Args:
| prompt_versions: List of PromptVersion objects to link.
| trace_id: Trace ID to link to each prompt version.
|
| Example:
| .. code-block:: python
|
| import mlflow
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Get prompt versions and link to trace
| prompt_v1 = client.get_prompt_version("my_prompt", "1")
| prompt_v2 = client.get_prompt_version("another_prompt", "2")
|
| client.link_prompt_versions_to_trace(
| prompt_versions=[prompt_v1, prompt_v2],
| trace_id="trace_123",
| )
|
| link_traces_to_run(self, trace_ids: list[str], run_id: str) -> None
| Link multiple traces to a run by creating entity associations.
|
| Args:
| trace_ids: List of trace IDs to link to the run. Maximum 100 traces allowed.
| run_id: ID of the run to link traces to.
|
| Example:
| .. code-block:: python
|
| import mlflow
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Link multiple traces to a run
| client.link_traces_to_run(
| trace_ids=["trace_123", "trace_456", "trace_789"],
| run_id="run_abc",
| )
|
| list_artifacts(self, run_id: str, path=None) -> list[mlflow.entities.file_info.FileInfo]
| List the artifacts for a run.
|
| Args:
| run_id: The run to list artifacts from.
| path: The run's relative artifact path to list from. By default it is set to None
| or the root artifact path.
|
| Returns:
| List of :py:class:`mlflow.entities.FileInfo`
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_artifact_info(artifact):
| print(f"artifact: {artifact.path}")
| print(f"is_dir: {artifact.is_dir}")
| print(f"size: {artifact.file_size}")
|
|
| features = "rooms zipcode, median_price, school_rating, transport"
| labels = "price"
|
| # Create a run under the default experiment (whose id is '0').
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
|
| # Create some artifacts and log under the above run
| for file, content in [("features", features), ("labels", labels)]:
| with open(f"{file}.txt", "w") as f:
| f.write(content)
| client.log_artifact(run.info.run_id, f"{file}.txt")
|
| # Fetch the logged artifacts
| artifacts = client.list_artifacts(run.info.run_id)
| for artifact in artifacts:
| print_artifact_info(artifact)
| client.set_terminated(run.info.run_id)
|
| .. code-block:: text
| :caption: Output
|
| artifact: features.txt
| is_dir: False
| size: 53
| artifact: labels.txt
| is_dir: False
| size: 5
|
| list_logged_model_artifacts(self, model_id: str, path: str | None = None) -> list[mlflow.entities.file_info.FileInfo]
|
| list_logged_prompts(self, run_id: str) -> list[mlflow.entities.model_registry.prompt_version.PromptVersion]
| List all prompts associated with an MLflow Run.
|
| Args:
| run_id: The ID of the run to list the prompts for.
|
| Returns:
| A list of :py:class:`Prompt <mlflow.entities.Prompt>` objects associated with the run.
|
| list_webhooks(self, max_results: int | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.webhook.Webhook]
| List webhooks.
|
| Args:
| max_results: Maximum number of webhooks to return.
| page_token: Token specifying the next page of results.
|
| Returns:
| A :py:class:`mlflow.store.entities.paged_list.PagedList` of Webhook objects.
|
| list_workspaces(self) -> list[mlflow.entities.workspace.Workspace]
| Return the list of workspaces available to the current user.
|
| load_prompt(self, name_or_uri: str, version: str | int | None = None, allow_missing: bool = False, cache_ttl_seconds: float | None = None) -> mlflow.entities.model_registry.prompt_version.PromptVersion | None
| Load a :py:class:`Prompt <mlflow.entities.Prompt>` from the MLflow Prompt Registry.
|
| The prompt can be specified by name and version, or by URI.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient(registry_uri="sqlite:///prompt_registry.db")
|
| # Load a specific version of the prompt by name and version
| prompt = client.load_prompt("my_prompt", version=1)
|
| # Load a specific version of the prompt by URI
| prompt = client.load_prompt("prompts:/my_prompt/1")
|
| Args:
| name_or_uri: The name of the prompt, or the URI in the format "prompts:/name/version".
| version: The version of the prompt (required when using name, not allowed when
| using URI).
| allow_missing: If True, return None instead of raising Exception if the specified prompt
| is not found.
| cache_ttl_seconds: Time-to-live for caching the prompt in seconds. If None, uses
| the value from `MLFLOW_ALIAS_PROMPT_CACHE_TTL_SECONDS` environment variable for
| alias-based prompts (default 60), and the value from
| `MLFLOW_VERSION_PROMPT_CACHE_TTL_SECONDS` environment variable for version-based
| prompts (default None, no TTL). Set to 0 to disable caching.
|
| load_table(self, experiment_id: str, artifact_file: str, run_ids: list[str] | None = None, extra_columns: list[str] | None = None) -> 'pandas.DataFrame'
| Load a table from MLflow Tracking as a pandas.DataFrame. The table is loaded from the
| specified artifact_file in the specified run_ids. The extra_columns are columns that
| are not in the table but are augmented with run information and added to the DataFrame.
|
| Args:
| experiment_id: The experiment ID to load the table from.
| artifact_file: The run-relative artifact file path in posixpath format to which
| table to load (e.g. "dir/file.json").
| run_ids: Optional list of run_ids to load the table from. If no run_ids are
| specified, the table is loaded from all runs in the current experiment.
| extra_columns: Optional list of extra columns to add to the returned DataFrame
| For example, if extra_columns=["run_id"], then the returned DataFrame
| will have a column named run_id.
|
| Returns:
| pandas.DataFrame containing the loaded table if the artifact exists
| or else throw a MlflowException.
|
| .. code-block:: python
| :test:
| :caption: Example with passing run_ids
|
| import mlflow
| import pandas as pd
| from mlflow import MlflowClient
|
| table_dict = {
| "inputs": ["What is MLflow?", "What is Databricks?"],
| "outputs": ["MLflow is ...", "Databricks is ..."],
| "toxicity": [0.0, 0.0],
| }
| df = pd.DataFrame.from_dict(table_dict)
| client = MlflowClient()
| run = client.create_run(experiment_id="0")
| client.log_table(run.info.run_id, data=df, artifact_file="qabot_eval_results.json")
| loaded_table = client.load_table(
| experiment_id="0",
| artifact_file="qabot_eval_results.json",
| run_ids=[
| run.info.run_id,
| ],
| # Append a column containing the associated run ID for each row
| extra_columns=["run_id"],
| )
|
| .. code-block:: python
| :test:
| :caption: Example with passing no run_ids
|
| # Loads the table with the specified name for all runs in the given
| # experiment and joins them together
| import mlflow
| import pandas as pd
| from mlflow import MlflowClient
|
| table_dict = {
| "inputs": ["What is MLflow?", "What is Databricks?"],
| "outputs": ["MLflow is ...", "Databricks is ..."],
| "toxicity": [0.0, 0.0],
| }
| df = pd.DataFrame.from_dict(table_dict)
| client = MlflowClient()
| run = client.create_run(experiment_id="0")
| client.log_table(run.info.run_id, data=df, artifact_file="qabot_eval_results.json")
| loaded_table = client.load_table(
| experiment_id="0",
| artifact_file="qabot_eval_results.json",
| # Append the run ID and the parent run ID to the table
| extra_columns=["run_id"],
| )
|
| log_artifact(self, run_id, local_path, artifact_path=None) -> None
| Write a local file or directory to the remote ``artifact_uri``.
|
| Args:
| run_id: String ID of run.
| local_path: Path to the file or directory to write.
| artifact_path: If provided, the directory in ``artifact_uri`` to write to.
|
| .. code-block:: python
| :caption: Example
|
| import tempfile
| from pathlib import Path
|
| from mlflow import MlflowClient
|
| # Create a run under the default experiment (whose id is '0').
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
|
| # log and fetch the artifact
| with tempfile.TemporaryDirectory() as tmp_dir:
| path = Path(tmp_dir, "features.txt")
| path.write_text(features)
| client.log_artifact(run.info.run_id, path)
|
| artifacts = client.list_artifacts(run.info.run_id)
| for artifact in artifacts:
| print(f"artifact: {artifact.path}")
| print(f"is_dir: {artifact.is_dir}")
| client.set_terminated(run.info.run_id)
|
| .. code-block:: text
| :caption: Output
|
| artifact: features.txt
| is_dir: False
|
| log_artifacts(self, run_id: str, local_dir: str, artifact_path: str | None = None) -> None
| Write a directory of files to the remote ``artifact_uri``.
|
| Args:
| run_id: String ID of run.
| local_dir: Path to the directory of files to write.
| artifact_path: If provided, the directory in ``artifact_uri`` to write to.
|
| .. code-block:: python
| :caption: Example
|
| import json
| import tempfile
| from pathlib import Path
|
| # Create some artifacts data to preserve
| features = "rooms, zipcode, median_price, school_rating, transport"
| data = {"state": "TX", "Available": 25, "Type": "Detached"}
| with tempfile.TemporaryDirectory() as tmp_dir:
| tmp_dir = Path(tmp_dir)
| with (tmp_dir / "data.json").open("w") as f:
| json.dump(data, f, indent=2)
| with (tmp_dir / "features.json").open("w") as f:
| f.write(features)
|
| # Create a run under the default experiment (whose id is '0'), and log
| # all files in "data" to root artifact_uri/states
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| client.log_artifacts(run.info.run_id, tmp_dir, artifact_path="states")
|
| artifacts = client.list_artifacts(run.info.run_id)
| for artifact in artifacts:
| print(f"artifact: {artifact.path}")
| print(f"is_dir: {artifact.is_dir}")
| client.set_terminated(run.info.run_id)
|
| .. code-block:: text
| :caption: Output
|
| artifact: states
| is_dir: True
|
| log_batch(self, run_id: str, metrics: Sequence[mlflow.entities.metric.Metric] = (), params: Sequence[mlflow.entities.param.Param] = (), tags: Sequence[mlflow.entities.run_tag.RunTag] = (), synchronous: bool | None = None) -> mlflow.utils.async_logging.run_operations.RunOperations | None
| Log multiple metrics, params, and/or tags.
|
| Args:
| run_id: String ID of the run
| metrics: If provided, List of Metric(key, value, timestamp) instances.
| params: If provided, List of Param(key, value) instances.
| tags: If provided, List of RunTag(key, value) instances.
| synchronous: *Experimental* If True, blocks until the metric is logged successfully.
| If False, logs the metric asynchronously and returns a future representing the
| logging operation. If None, read from environment variable
| `MLFLOW_ENABLE_ASYNC_LOGGING`, which defaults to False if not set.
|
| Raises:
| mlflow.MlflowException: If any errors occur.
|
| Returns:
| When `synchronous=True` or None, returns None. When `synchronous=False`, returns an
| :py:class:`mlflow.utils.async_logging.run_operations.RunOperations` instance that
| represents future for logging operation.
|
| .. code-block:: python
| :caption: Example
|
| import time
|
| from mlflow import MlflowClient
| from mlflow.entities import Metric, Param, RunTag
|
|
| def print_run_info(r):
| print(f"run_id: {r.info.run_id}")
| print(f"params: {r.data.params}")
| print(f"metrics: {r.data.metrics}")
| print(f"tags: {r.data.tags}")
| print(f"status: {r.info.status}")
|
|
| # Create MLflow entities and a run under the default experiment (whose id is '0').
| timestamp = int(time.time() * 1000)
| metrics = [Metric("m", 1.5, timestamp, 1)]
| params = [Param("p", "p")]
| tags = [RunTag("t", "t")]
| experiment_id = "0"
| client = MlflowClient()
| run = client.create_run(experiment_id)
|
| # Log entities, terminate the run, and fetch run status
| client.log_batch(run.info.run_id, metrics=metrics, params=params, tags=tags)
| client.set_terminated(run.info.run_id)
| run = client.get_run(run.info.run_id)
| print_run_info(run)
|
| # To log metric in async fashion
| client.log_metric(run.info.run_id, "m", 1.5, synchronous=False)
|
| .. code-block:: text
| :caption: Output
|
| run_id: ef0247fa3205410595acc0f30f620871
| params: {'p': 'p'}
| metrics: {'m': 1.5}
| tags: {'t': 't'}
| status: FINISHED
|
| log_dict(self, run_id: str, dictionary: dict[str, typing.Any], artifact_file: str) -> None
| Log a JSON/YAML-serializable object (e.g. `dict`) as an artifact. The serialization
| format (JSON or YAML) is automatically inferred from the extension of `artifact_file`.
| If the file extension doesn't exist or match any of [".json", ".yml", ".yaml"],
| JSON format is used, and we stringify objects that can't be JSON-serialized.
|
| Args:
| run_id: String ID of the run.
| dictionary: Dictionary to log.
| artifact_file: The run-relative artifact file path in posixpath format to which
| the dictionary is saved (e.g. "dir/data.json").
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| run = client.create_run(experiment_id="0")
| run_id = run.info.run_id
|
| dictionary = {"k": "v"}
|
| # Log a dictionary as a JSON file under the run's root artifact directory
| client.log_dict(run_id, dictionary, "data.json")
|
| # Log a dictionary as a YAML file in a subdirectory of the run's root artifact directory
| client.log_dict(run_id, dictionary, "dir/data.yml")
|
| # If the file extension doesn't exist or match any of [".json", ".yaml", ".yml"],
| # JSON format is used.
| mlflow.log_dict(run_id, dictionary, "data")
| mlflow.log_dict(run_id, dictionary, "data.txt")
|
| log_figure(self, run_id: str, figure: Union[ForwardRef('matplotlib.figure.Figure'), ForwardRef('plotly.graph_objects.Figure')], artifact_file: str, *, save_kwargs: dict[str, typing.Any] | None = None) -> None
| Log a figure as an artifact. The following figure objects are supported:
|
| - `matplotlib.figure.Figure`_
| - `plotly.graph_objects.Figure`_
|
| .. _matplotlib.figure.Figure:
| https://matplotlib.org/api/_as_gen/matplotlib.figure.Figure.html
|
| .. _plotly.graph_objects.Figure:
| https://plotly.com/python-api-reference/generated/plotly.graph_objects.Figure.html
|
| Args:
| run_id: String ID of the run.
| figure: Figure to log.
| artifact_file: The run-relative artifact file path in posixpath format to which
| the figure is saved (e.g. "dir/file.png").
| save_kwargs: Additional keyword arguments passed to the method that saves the figure.
|
| .. code-block:: python
| :caption: Matplotlib Example
|
| import mlflow
| import matplotlib.pyplot as plt
|
| fig, ax = plt.subplots()
| ax.plot([0, 1], [2, 3])
|
| run = client.create_run(experiment_id="0")
| client.log_figure(run.info.run_id, fig, "figure.png")
|
| .. code-block:: python
| :caption: Plotly Example
|
| import mlflow
| from plotly import graph_objects as go
|
| fig = go.Figure(go.Scatter(x=[0, 1], y=[2, 3]))
|
| run = client.create_run(experiment_id="0")
| client.log_figure(run.info.run_id, fig, "figure.html")
|
| log_image(self, run_id: str, image: Union[ForwardRef('numpy.ndarray'), ForwardRef('PIL.Image.Image'), ForwardRef('mlflow.Image')], artifact_file: str | None = None, key: str | None = None, step: int | None = None, timestamp: int | None = None, synchronous: bool | None = None) -> None
| Logs an image in MLflow, supporting two use cases:
|
| 1. Time-stepped image logging:
| Ideal for tracking changes or progressions through iterative processes (e.g.,
| during model training phases).
|
| - Usage: :code:`log_image(image, key=key, step=step, timestamp=timestamp)`
|
| 2. Artifact file image logging:
| Best suited for static image logging where the image is saved directly as a file
| artifact.
|
| - Usage: :code:`log_image(image, artifact_file)`
|
| The following image formats are supported:
| - `numpy.ndarray`_
| - `PIL.Image.Image`_
|
| .. _numpy.ndarray:
| https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html
|
| .. _PIL.Image.Image:
| https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image
|
| - :class:`mlflow.Image`: An MLflow wrapper around PIL image for convenient image
| logging.
|
| Numpy array support
| - data types:
|
| - bool (useful for logging image masks)
| - integer [0, 255]
| - unsigned integer [0, 255]
| - float [0.0, 1.0]
|
| .. warning::
|
| - Out-of-range integer values will raise ValueError.
| - Out-of-range float values will auto-scale with min/max and warn.
|
| - shape (H: height, W: width):
|
| - H x W (Grayscale)
| - H x W x 1 (Grayscale)
| - H x W x 3 (an RGB channel order is assumed)
| - H x W x 4 (an RGBA channel order is assumed)
|
| Args:
| run_id: String ID of run.
| image: The image object to be logged.
| artifact_file: Specifies the path, in POSIX format, where the image
| will be stored as an artifact relative to the run's root directory (for
| example, "dir/image.png"). This parameter is kept for backward compatibility
| and should not be used together with `key`, `step`, or `timestamp`.
| key: Image name for time-stepped image logging. This string may only contain
| alphanumerics, underscores (_), dashes (-), periods (.), spaces ( ), and
| slashes (/).
| step: Integer training step (iteration) at which the image was saved.
| Defaults to 0.
| timestamp: Time when this image was saved. Defaults to the current system time.
| synchronous: *Experimental* If True, blocks until the metric is logged successfully.
| If False, logs the metric asynchronously and returns a future representing the
| logging operation. If None, read from environment variable
| `MLFLOW_ENABLE_ASYNC_LOGGING`, which defaults to False if not set.
|
| .. code-block:: python
| :caption: Time-stepped image logging numpy example
|
| import mlflow
| import numpy as np
|
| image = np.random.randint(0, 256, size=(100, 100, 3), dtype=np.uint8)
| with mlflow.start_run() as run:
| client = mlflow.MlflowClient()
| client.log_image(run.info.run_id, image, key="dogs", step=3)
|
| .. code-block:: python
| :caption: Time-stepped image logging pillow example
|
| import mlflow
| from PIL import Image
|
| image = Image.new("RGB", (100, 100))
| with mlflow.start_run() as run:
| client = mlflow.MlflowClient()
| client.log_image(run.info.run_id, image, key="dogs", step=3)
|
| .. code-block:: python
| :caption: Time-stepped image logging with mlflow.Image example
|
| import mlflow
| from PIL import Image
|
| # Saving an image to retrieve later.
| Image.new("RGB", (100, 100)).save("image.png")
|
| image = mlflow.Image("image.png")
| with mlflow.start_run() as run:
| client = mlflow.MlflowClient()
| client.log_image(run.info.run_id, image, key="dogs", step=3)
|
| .. code-block:: python
| :caption: Legacy artifact file image logging numpy example
|
| import mlflow
| import numpy as np
|
| image = np.random.randint(0, 256, size=(100, 100, 3), dtype=np.uint8)
| with mlflow.start_run() as run:
| client = mlflow.MlflowClient()
| client.log_image(run.info.run_id, image, "image.png")
|
| .. code-block:: python
| :caption: Legacy artifact file image logging pillow example
|
| import mlflow
| from PIL import Image
|
| image = Image.new("RGB", (100, 100))
| with mlflow.start_run() as run:
| client = mlflow.MlflowClient()
| client.log_image(run.info.run_id, image, "image.png")
|
| log_inputs(self, run_id: str, datasets: Optional[Sequence[mlflow.entities.dataset_input.DatasetInput]] = None, models: Optional[Sequence[mlflow.entities.logged_model_input.LoggedModelInput]] = None) -> None
| Log one or more dataset inputs to a run.
|
| Args:
| run_id: String ID of the run.
| datasets: List of :py:class:`mlflow.entities.DatasetInput` instances to log.
| models: List of :py:class:`mlflow.entities.LoggedModelInput` instances to log.
|
| Raises:
| mlflow.MlflowException: If any errors occur.
|
| log_metric(self, run_id: str, key: str, value: float, timestamp: int | None = None, step: int | None = None, synchronous: bool | None = None, dataset_name: str | None = None, dataset_digest: str | None = None, model_id: str | None = None) -> mlflow.utils.async_logging.run_operations.RunOperations | None
| Log a metric against the run ID.
|
| Args:
| run_id: The run id to which the metric should be logged.
| key: Metric name. This string may only contain alphanumerics, underscores
| (_), dashes (-), periods (.), spaces ( ), and slashes (/).
| All backend stores will support keys up to length 250, but some may
| support larger keys.
| value: Metric value. Note that some special values such
| as +/- Infinity may be replaced by other values depending on the store. For
| example, the SQLAlchemy store replaces +/- Inf with max / min float values.
| All backend stores will support values up to length 5000, but some
| may support larger values.
| timestamp: Time when this metric was calculated. Defaults to the current system time.
| step: Integer training step (iteration) at which was the metric calculated.
| Defaults to 0.
| synchronous: *Experimental* If True, blocks until the metric is logged successfully.
| If False, logs the metric asynchronously and returns a future representing the
| logging operation. If None, read from environment variable
| `MLFLOW_ENABLE_ASYNC_LOGGING`, which defaults to False if not set.
| dataset_name: The name of the dataset associated with the metric. If specified,
| ``dataset_digest`` must also be provided.
| dataset_digest: The digest of the dataset associated with the metric. If specified,
| ``dataset_name`` must also be provided.
| model_id: The ID of the model associated with the metric. If not specified, use the
| current active model ID set by :py:func:`mlflow.set_active_model`.
|
| Returns:
| When `synchronous=True` or None, returns None. When `synchronous=False`, returns an
| :py:class:`mlflow.utils.async_logging.run_operations.RunOperations` instance that
| represents future for logging operation.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_run_info(r):
| print(f"run_id: {r.info.run_id}")
| print(f"metrics: {r.data.metrics}")
| print(f"status: {r.info.status}")
|
|
| # Create a run under the default experiment (whose id is '0').
| # Since these are low-level CRUD operations, this method will create a run.
| # To end the run, you'll have to explicitly end it.
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| print_run_info(run)
| print("--")
|
| # Log the metric. Unlike mlflow.log_metric this method
| # does not start a run if one does not exist. It will log
| # the metric for the run id in the backend store.
| client.log_metric(run.info.run_id, "m", 1.5)
| client.set_terminated(run.info.run_id)
| run = client.get_run(run.info.run_id)
| print_run_info(run)
|
| # To log metric in async fashion
| client.log_metric(run.info.run_id, "m", 1.5, synchronous=False)
|
| .. code-block:: text
| :caption: Output
|
| run_id: 95e79843cb2c463187043d9065185e24
| metrics: {}
| status: RUNNING
| --
| run_id: 95e79843cb2c463187043d9065185e24
| metrics: {'m': 1.5}
| status: FINISHED
|
| log_model_artifact(self, model_id: str, local_path: str) -> None
| Upload an artifact to the specified logged model.
|
| Args:
| model_id: ID of the model.
| local_path: Local path to the artifact to upload.
|
| Returns:
| None
|
| log_model_artifacts(self, model_id: str, local_dir: str) -> None
| Upload a set of artifacts to the specified logged model.
|
| Args:
| model_id: ID of the model.
| local_dir: Local directory containing the artifacts to upload.
|
| Returns:
| None
|
| log_model_params(self, model_id: str, params: dict[str, str]) -> None
| Log parameters for a logged model.
|
| Args:
| model_id: ID of the model to log parameters for.
| params: Dictionary of parameters to log.
|
| Returns:
| None
|
| log_outputs(self, run_id: str, models: list[mlflow.entities.logged_model_output.LoggedModelOutput])
|
| log_param(self, run_id: str, key: str, value: Any, synchronous: bool | None = None) -> Any
| Log a parameter (e.g. model hyperparameter) against the run ID.
|
| Args:
| run_id: The run id to which the param should be logged.
| key: Parameter name. This string may only contain alphanumerics, underscores
| (_), dashes (-), periods (.), spaces ( ), and slashes (/).
| All backend stores support keys up to length 250, but some may
| support larger keys.
| value: Parameter value, but will be string-ified if not.
| All built-in backend stores support values up to length 6000, but some
| may support larger values.
| synchronous: *Experimental* If True, blocks until the metric is logged successfully.
| If False, logs the metric asynchronously and returns a future representing the
| logging operation. If None, read from environment variable
| `MLFLOW_ENABLE_ASYNC_LOGGING`, which defaults to False if not set.
|
| Returns:
| When `synchronous=True` or None, returns parameter value. When `synchronous=False`,
| returns an :py:class:`mlflow.utils.async_logging.run_operations.RunOperations`
| instance that represents future for logging operation.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_run_info(r):
| print(f"run_id: {r.info.run_id}")
| print(f"params: {r.data.params}")
| print(f"status: {r.info.status}")
|
|
| # Create a run under the default experiment (whose id is '0').
| # Since these are low-level CRUD operations, this method will create a run.
| # To end the run, you'll have to explicitly end it.
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| print_run_info(run)
| print("--")
| # Log the parameter. Unlike mlflow.log_param this method
| # does not start a run if one does not exist. It will log
| # the parameter in the backend store
| p_value = client.log_param(run.info.run_id, "p", 1)
| assert p_value == 1
| client.set_terminated(run.info.run_id)
| run = client.get_run(run.info.run_id)
| print_run_info(run)
|
| .. code-block:: text
| :caption: Output
|
| run_id: e649e49c7b504be48ee3ae33c0e76c93
| params: {}
| status: RUNNING
| --
| run_id: e649e49c7b504be48ee3ae33c0e76c93
| params: {'p': '1'}
| status: FINISHED
|
| log_stream(self, run_id: str, stream: io.BufferedIOBase | io.RawIOBase, artifact_file: str) -> None
| .. Note:: Experimental: This function may change or be removed in a future release without warning.
|
|
| Log a binary file-like object (e.g., ``io.BytesIO``) as an artifact.
|
| Args:
| run_id: String ID of the run.
| stream: A binary file-like object supporting ``.read()`` method
| (e.g., ``io.BytesIO``).
| artifact_file: The run-relative artifact file path in posixpath format to which
| the stream content is saved (e.g. "dir/file.bin").
|
| .. code-block:: python
| :caption: Example
|
| import io
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| run = client.create_run(experiment_id="0")
|
| # Log a BytesIO stream
| bytes_stream = io.BytesIO(b"binary content")
| client.log_stream(run.info.run_id, bytes_stream, "binary_file.bin")
|
| log_table(self, run_id: str, data: Union[dict[str, Any], ForwardRef('pandas.DataFrame')], artifact_file: str) -> None
| Log a table to MLflow Tracking as a JSON artifact. If the artifact_file already exists
| in the run, the data would be appended to the existing artifact_file.
|
| Args:
| run_id: String ID of the run.
| data: Dictionary or pandas.DataFrame to log.
| artifact_file: The run-relative artifact file path in posixpath format to which
| the table is saved (e.g. "dir/file.json").
|
| .. code-block:: python
| :test:
| :caption: Dictionary Example
|
| import mlflow
| from mlflow import MlflowClient
|
| table_dict = {
| "inputs": ["What is MLflow?", "What is Databricks?"],
| "outputs": ["MLflow is ...", "Databricks is ..."],
| "toxicity": [0.0, 0.0],
| }
| with mlflow.start_run() as run:
| client = MlflowClient()
| client.log_table(
| run.info.run_id, data=table_dict, artifact_file="qabot_eval_results.json"
| )
|
| .. code-block:: python
| :test:
| :caption: Pandas DF Example
|
| import mlflow
| import pandas as pd
| from mlflow import MlflowClient
|
| table_dict = {
| "inputs": ["What is MLflow?", "What is Databricks?"],
| "outputs": ["MLflow is ...", "Databricks is ..."],
| "toxicity": [0.0, 0.0],
| }
| df = pd.DataFrame.from_dict(table_dict)
| with mlflow.start_run() as run:
| client = MlflowClient()
| client.log_table(run.info.run_id, data=df, artifact_file="qabot_eval_results.json")
|
| .. code-block:: python
| :test:
| :caption: Image Column Example
|
| import mlflow
| import pandas as pd
| from mlflow import MlflowClient
|
| image = mlflow.Image([[1, 2, 3]])
| table_dict = {
| "inputs": ["Show me a dog", "Show me a cat"],
| "outputs": [image, image],
| }
| df = pd.DataFrame.from_dict(table_dict)
| with mlflow.start_run() as run:
| client = MlflowClient()
| client.log_table(run.info.run_id, data=df, artifact_file="image_gen.json")
|
| log_text(self, run_id: str, text: str, artifact_file: str) -> None
| Log text as an artifact.
|
| Args:
| run_id: String ID of the run.
| text: String containing text to log.
| artifact_file: The run-relative artifact file path in posixpath format to which
| the text is saved (e.g. "dir/file.txt").
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| run = client.create_run(experiment_id="0")
|
| # Log text to a file under the run's root artifact directory
| client.log_text(run.info.run_id, "text1", "file1.txt")
|
| # Log text in a subdirectory of the run's root artifact directory
| client.log_text(run.info.run_id, "text2", "dir/file2.txt")
|
| # Log HTML text
| client.log_text(run.info.run_id, "<h1>header</h1>", "index.html")
|
| parse_prompt_uri(self, uri: str) -> tuple[str, str]
| Parse prompt URI into prompt name and prompt version.
| - 'prompts:/<name>/<version>' -> ('<name>', '<version>')
| - 'prompts:/<name>@<alias>' -> ('<name>', '<version>')
|
| This method reuses the existing model URI parsing logic with prompts prefix.
|
| refresh_mcp_server_version_tools(self, name: str, version: str, mcp_server_access_headers: Optional[Mapping[str, str]] = None, dry_run: bool = False) -> mlflow.entities.mcp_server_version.MCPServerVersion
|
| register_prompt(self, name: str, template: str | list[dict[str, typing.Any]], commit_message: str | None = None, tags: dict[str, str] | None = None, response_format: type[pydantic.main.BaseModel] | dict[str, typing.Any] | None = None, model_config: 'PromptModelConfig | dict[str, Any] | None' = None) -> mlflow.entities.model_registry.prompt_version.PromptVersion
| Register a new :py:class:`Prompt <mlflow.entities.Prompt>` in the MLflow Prompt Registry.
|
| A :py:class:`Prompt <mlflow.entities.Prompt>` is a pair of name
| and template content at minimum. With MLflow Prompt Registry, you can create, manage,
| and version control prompts with the MLflow's robust model tracking framework.
|
| If there is no registered prompt with the given name, a new prompt will be created.
| Otherwise, a new version of the existing prompt will be created.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
| from pydantic import BaseModel
|
| # Your prompt registry URI
| client = MlflowClient(registry_uri="sqlite:///prompt_registry.db")
|
| # Register a text prompt
| client.register_prompt(
| name="greeting_prompt",
| template="Respond to the user's message as a {{style}} AI.",
| response_format={"type": "string", "description": "A friendly response"},
| )
|
| # Register a chat prompt with multiple messages
| client.register_prompt(
| name="assistant_prompt",
| template=[
| {"role": "system", "content": "You are a helpful {{style}} assistant."},
| {"role": "user", "content": "{{question}}"},
| ],
| response_format={"type": "object", "properties": {"answer": {"type": "string"}}},
| )
|
| # Load the prompt from the registry
| prompt = client.load_prompt("greeting_prompt")
|
| # Use the prompt in your application
| import openai
|
| openai_client = openai.OpenAI()
| openai_client.chat.completion.create(
| model="gpt-4o-mini",
| messages=[
| {"role": "system", "content": prompt.format(style="friendly")},
| {"role": "user", "content": "Hello, how are you?"},
| ],
| )
|
| # Update the prompt with a new version
| prompt = client.register_prompt(
| name="greeting_prompt",
| template="Respond to the user's message as a {{style}} AI. {{greeting}}",
| commit_message="Add a greeting to the prompt.",
| tags={"author": "Bob"},
| )
|
| Args:
| name: The name of the prompt.
| template: The template content of the prompt. Can be either:
|
| - A string containing text with variables enclosed in double curly braces,
| e.g. {{variable}}, which will be replaced with actual values by the `format`
| method.
| - A list of dictionaries representing chat messages, where each message has
| 'role' and 'content' keys (e.g., [{"role": "user", "content": "Hello {{name}}"}])
|
| commit_message: A message describing the changes made to the prompt, similar to a
| Git commit message. Optional.
| tags: A dictionary of tags for the prompt.
| These tags are stored on the prompt version and written to prompt-level metadata.
| For OSS, later ``register_prompt()`` calls can overwrite the same keys at the
| prompt level. Optional.
| response_format: Optional Pydantic class or dictionary defining the expected response
| structure. This can be used to specify the schema for structured outputs from LLM
| calls.
| model_config: Optional PromptModelConfig instance or dictionary containing
| model-specific configuration like model_name, temperature, max_tokens, etc.
| Using PromptModelConfig provides validation and type safety.
|
| Returns:
| A :py:class:`Prompt <mlflow.entities.Prompt>` object that was created.
|
| remove_dataset_from_experiments(self, dataset_id: str, experiment_ids: list[str]) -> mlflow.entities.evaluation_dataset.EvaluationDataset
| Remove a dataset from experiments.
|
| This operation is idempotent - removing non-existent associations will not raise errors.
|
| Args:
| dataset_id: The ID of the dataset to update.
| experiment_ids: List of experiment IDs to remove association from.
|
| Returns:
| The updated EvaluationDataset with removed experiment associations.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Remove dataset from experiments
| dataset = client.remove_dataset_from_experiments(
| dataset_id="d-abc123", experiment_ids=["2", "3"]
| )
| print(f"Dataset now associated with {len(dataset.experiment_ids)} experiments")
|
| rename_experiment(self, experiment_id: str, new_name: str) -> None
| Update an experiment's name. The new name must be unique.
|
| Args:
| experiment_id: The experiment ID returned from ``create_experiment``.
| new_name: The new name for the experiment.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_experiment_info(experiment):
| print(f"Name: {experiment.name}")
| print(f"Experiment_id: {experiment.experiment_id}")
| print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
|
|
| # Create an experiment with a name that is unique and case sensitive
| client = MlflowClient()
| experiment_id = client.create_experiment("Social NLP Experiments")
|
| # Fetch experiment metadata information
| experiment = client.get_experiment(experiment_id)
| print_experiment_info(experiment)
| print("--")
|
| # Rename and fetch experiment metadata information
| client.rename_experiment(experiment_id, "Social Media NLP Experiments")
| experiment = client.get_experiment(experiment_id)
| print_experiment_info(experiment)
|
| .. code-block:: text
| :caption: Output
|
| Name: Social NLP Experiments
| Experiment_id: 1
| Lifecycle_stage: active
| --
| Name: Social Media NLP Experiments
| Experiment_id: 1
| Lifecycle_stage: active
|
| rename_registered_model(self, name: str, new_name: str) -> mlflow.entities.model_registry.registered_model.RegisteredModel
| Update registered model name.
|
| Args:
| name: Name of the registered model to update.
| new_name: New proposed name for the registered model.
|
| Returns:
| A single updated :py:class:`mlflow.entities.model_registry.RegisteredModel` object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
|
| def print_registered_model_info(rm):
| print(f"name: {rm.name}")
| print(f"tags: {rm.tags}")
| print(f"description: {rm.description}")
|
|
| name = "SocialTextAnalyzer"
| tags = {"nlp.framework": "Spark NLP"}
| desc = "This sentiment analysis model classifies the tone-happy, sad, angry."
|
| # create a new registered model name
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| client = MlflowClient()
| client.create_registered_model(name, tags, desc)
| print_registered_model_info(client.get_registered_model(name))
| print("--")
|
| # rename the model
| new_name = "SocialMediaTextAnalyzer"
| client.rename_registered_model(name, new_name)
| print_registered_model_info(client.get_registered_model(new_name))
|
| .. code-block:: text
| :caption: Output
|
| name: SocialTextAnalyzer
| tags: {'nlp.framework': 'Spark NLP'}
| description: This sentiment analysis model classifies the tone-happy, sad, angry.
| --
| name: SocialMediaTextAnalyzer
| tags: {'nlp.framework': 'Spark NLP'}
| description: This sentiment analysis model classifies the tone-happy, sad, angry.
|
| restore_experiment(self, experiment_id: str) -> None
| Restore a deleted experiment unless permanently deleted.
|
| Args:
| experiment_id: The experiment ID returned from ``create_experiment``.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_experiment_info(experiment):
| print(f"Name: {experiment.name}")
| print(f"Experiment Id: {experiment.experiment_id}")
| print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
|
|
| # Create and delete an experiment
| client = MlflowClient()
| experiment_id = client.create_experiment("New Experiment")
| client.delete_experiment(experiment_id)
|
| # Examine the deleted experiment details.
| experiment = client.get_experiment(experiment_id)
| print_experiment_info(experiment)
| print("--")
|
| # Restore the experiment and fetch its info
| client.restore_experiment(experiment_id)
| experiment = client.get_experiment(experiment_id)
| print_experiment_info(experiment)
|
| .. code-block:: text
| :caption: Output
|
| Name: New Experiment
| Experiment Id: 1
| Lifecycle_stage: deleted
| --
| Name: New Experiment
| Experiment Id: 1
| Lifecycle_stage: active
|
| restore_run(self, run_id: str) -> None
| Restores a deleted run with the given ID.
|
| Args:
| run_id: The unique run id to restore.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| # Create a run under the default experiment (whose id is '0').
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| run_id = run.info.run_id
| print(f"run_id: {run_id}; lifecycle_stage: {run.info.lifecycle_stage}")
| client.delete_run(run_id)
| del_run = client.get_run(run_id)
| print(f"run_id: {run_id}; lifecycle_stage: {del_run.info.lifecycle_stage}")
| client.restore_run(run_id)
| rest_run = client.get_run(run_id)
| print(f"run_id: {run_id}; lifecycle_stage: {rest_run.info.lifecycle_stage}")
|
| .. code-block:: text
| :caption: Output
|
| run_id: 7bc59754d7e74534a7917d62f2873ac0; lifecycle_stage: active
| run_id: 7bc59754d7e74534a7917d62f2873ac0; lifecycle_stage: deleted
| run_id: 7bc59754d7e74534a7917d62f2873ac0; lifecycle_stage: active
|
| search_datasets(self, experiment_ids: list[str] | None = None, filter_string: str | None = None, max_results: int = 50, order_by: list[str] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.evaluation_dataset.EvaluationDataset]
| Search for datasets.
|
| Args:
| experiment_ids: List of experiment IDs to filter by.
| filter_string: A filter string to apply to the search.
| max_results: Maximum number of results to return. Defaults to 50.
| order_by: List of columns to order by.
| page_token: Token for the next page of results.
|
| Returns:
| A PagedList of EvaluationDataset objects.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Search for datasets in specific experiments
| datasets = client.search_datasets(
| experiment_ids=["exp1", "exp2"], filter_string="name LIKE 'qa_%'", max_results=10
| )
|
| # Get next page if available
| if datasets.token:
| next_page = client.search_datasets(
| experiment_ids=["exp1", "exp2"], page_token=datasets.token
| )
|
| search_experiments(self, view_type: int = 1, max_results: int | None = 1000, filter_string: str | None = None, order_by: list[str] | None = None, page_token=None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.experiment.Experiment]
| Search for experiments that match the specified search query.
|
| Args:
| view_type: One of enum values ``ACTIVE_ONLY``, ``DELETED_ONLY``, or ``ALL``
| defined in :py:class:`mlflow.entities.ViewType`.
| max_results: Maximum number of experiments desired. Certain server backend may apply
| its own limit.
| filter_string: Filter query string (e.g., ``"name = 'my_experiment'"``), defaults to
| searching for all experiments. The following identifiers, comparators, and logical
| operators are supported.
|
| Identifiers
| - ``name``: Experiment name
| - ``creation_time``: Experiment creation time
| - ``last_update_time``: Experiment last update time
| - ``tags.<tag_key>``: Experiment tag. If ``tag_key`` contains
| spaces, it must be wrapped with backticks (e.g., ``"tags.`extra key`"``).
|
| Comparators for string attributes and tags
| - ``=``: Equal to
| - ``!=``: Not equal to
| - ``LIKE``: Case-sensitive pattern match
| - ``ILIKE``: Case-insensitive pattern match
|
| Comparators for numeric attributes
| - ``=``: Equal to
| - ``!=``: Not equal to
| - ``<``: Less than
| - ``<=``: Less than or equal to
| - ``>``: Greater than
| - ``>=``: Greater than or equal to
|
| Logical operators
| - ``AND``: Combines two sub-queries and returns True if both of them are True.
|
| order_by: List of columns to order by. The ``order_by`` column can contain an optional
| ``DESC`` or ``ASC`` value (e.g., ``"name DESC"``). The default ordering is ``ASC``,
| so ``"name"`` is equivalent to ``"name ASC"``. If unspecified, defaults to
| ``["last_update_time DESC"]``, which lists experiments updated most recently first.
| The following fields are supported:
|
| - ``experiment_id``: Experiment ID
| - ``name``: Experiment name
| - ``creation_time``: Experiment creation time
| - ``last_update_time``: Experiment last update time
|
| page_token: Token specifying the next page of results. It should be obtained from
| a ``search_experiments`` call.
|
| Returns:
| A :py:class:`PagedList <mlflow.store.entities.PagedList>` of
| :py:class:`Experiment <mlflow.entities.Experiment>` objects. The pagination token
| for the next page can be obtained via the ``token`` attribute of the object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
|
|
| def assert_experiment_names_equal(experiments, expected_names):
| actual_names = [e.name for e in experiments if e.name != "Default"]
| assert actual_names == expected_names, (actual_names, expected_names)
|
|
| mlflow.set_tracking_uri("sqlite:///:memory:")
| client = mlflow.MlflowClient()
|
| # Create experiments
| for name, tags in [
| ("a", None),
| ("b", None),
| ("ab", {"k": "v"}),
| ("bb", {"k": "V"}),
| ]:
| client.create_experiment(name, tags=tags)
|
| # Search for experiments with name "a"
| experiments = client.search_experiments(filter_string="name = 'a'")
| assert_experiment_names_equal(experiments, ["a"])
|
| # Search for experiments with name starting with "a"
| experiments = client.search_experiments(filter_string="name LIKE 'a%'")
| assert_experiment_names_equal(experiments, ["ab", "a"])
|
| # Search for experiments with tag key "k" and value ending with "v" or "V"
| experiments = client.search_experiments(filter_string="tags.k ILIKE '%v'")
| assert_experiment_names_equal(experiments, ["bb", "ab"])
|
| # Search for experiments with name ending with "b" and tag {"k": "v"}
| experiments = client.search_experiments(filter_string="name LIKE '%b' AND tags.k = 'v'")
| assert_experiment_names_equal(experiments, ["ab"])
|
| # Sort experiments by name in ascending order
| experiments = client.search_experiments(order_by=["name"])
| assert_experiment_names_equal(experiments, ["a", "ab", "b", "bb"])
|
| # Sort experiments by ID in descending order
| experiments = client.search_experiments(order_by=["experiment_id DESC"])
| assert_experiment_names_equal(experiments, ["bb", "ab", "b", "a"])
|
| search_logged_models(self, experiment_ids: list[str], filter_string: str | None = None, datasets: list[dict[str, typing.Any]] | None = None, max_results: int | None = None, order_by: list[dict[str, typing.Any]] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.logged_model.LoggedModel]
| Search for logged models that match the specified search criteria.
|
| Args:
| experiment_ids: List of experiment ids to scope the search.
| filter_string: A SQL-like filter string to parse. The filter string syntax supports:
|
| - Entity specification:
| - attributes: `attribute_name` (default if no prefix is specified)
| - metrics: `metrics.metric_name`
| - parameters: `params.param_name`
| - tags: `tags.tag_name`
| - Comparison operators:
| - For numeric entities (metrics and numeric attributes): <, <=, >, >=, =, !=
| - For string entities (params, tags, string attributes): =, !=, IN, NOT IN
| - Multiple conditions can be joined with 'AND'
| - String values must be enclosed in single quotes
|
| Example filter strings:
| - `creation_time > 100`
| - `metrics.rmse > 0.5 AND params.model_type = 'rf'`
| - `tags.release IN ('v1.0', 'v1.1')`
| - `params.optimizer != 'adam' AND metrics.accuracy >= 0.9`
| datasets: List of dictionaries to specify datasets on which to apply metrics filters
| For example, a filter string with `metrics.accuracy > 0.9` and dataset with name
| "test_dataset" means we will return all logged models with accuracy > 0.9 on the
| test_dataset. Metric values from ANY dataset matching the criteria are considered.
| If no datasets are specified, then metrics across all datasets are considered in
| the filter. The following fields are supported:
|
| dataset_name (str):
| Required. Name of the dataset.
| dataset_digest (str):
| Optional. Digest of the dataset.
| max_results: Maximum number of logged models desired.
| order_by: List of dictionaries to specify the ordering of the search results.
| The following fields are supported:
|
| field_name (str):
| Required. Name of the field to order by, e.g. "metrics.accuracy".
| ascending (bool):
| Optional. Whether the order is ascending or not.
| dataset_name (str):
| Optional. If ``field_name`` refers to a metric, this field
| specifies the name of the dataset associated with the metric. Only metrics
| associated with the specified dataset name will be considered for ordering.
| This field may only be set if ``field_name`` refers to a metric.
| dataset_digest (str):
| Optional. If ``field_name`` refers to a metric, this field
| specifies the digest of the dataset associated with the metric. Only metrics
| associated with the specified dataset name and digest will be considered for
| ordering. This field may only be set if ``dataset_name`` is also set.
| page_token: Token specifying the next page of results.
|
| Returns:
| A :py:class:`PagedList <mlflow.store.entities.PagedList>` of
| :py:class:`LoggedModel <mlflow.entities.LoggedModel>` objects.
|
| search_mcp_access_endpoints(self, server_name: str | None = None, server_version: str | None = None, server_alias: str | None = None, filter_string: str | None = None, max_results: int = 1000, order_by: list[str] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.mcp_access_endpoint.MCPAccessEndpoint]
|
| search_mcp_server_versions(self, name: str, filter_string: str | None = None, max_results: int = 1000, order_by: list[str] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.mcp_server_version.MCPServerVersion]
|
| search_mcp_servers(self, filter_string: str | None = None, max_results: int = 1000, order_by: list[str] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.mcp_server.MCPServer]
|
| search_model_versions(self, filter_string: str | None = None, max_results: int = 10000, order_by: list[str] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.model_registry.model_version.ModelVersion]
| Search for model versions in backend that satisfy the filter criteria.
|
| .. warning:
| The model version search results may not have aliases populated for performance reasons.
|
| Args:
| filter_string: Filter query string
| (e.g., ``"name = 'a_model_name' and tag.key = 'value1'"``),
| defaults to searching for all model versions. The following identifiers,
| comparators, and logical operators are supported.
|
| Identifiers
| - ``name``: model name.
| - ``source_path``: model version source path.
| - ``run_id``: The id of the mlflow run that generates the model version.
| - ``tags.<tag_key>``: model version tag. If ``tag_key`` contains spaces, it must
| be wrapped with backticks (e.g., ``"tags.`extra key`"``).
|
| Comparators
| - ``=``: Equal to.
| - ``!=``: Not equal to.
| - ``LIKE``: Case-sensitive pattern match.
| - ``ILIKE``: Case-insensitive pattern match.
| - ``IN``: In a value list. Only ``run_id`` identifier supports ``IN`` comparator.
|
| Logical operators
| - ``AND``: Combines two sub-queries and returns True if both of them are True.
|
| max_results: Maximum number of model versions desired.
| order_by: List of column names with ASC|DESC annotation, to be used for ordering
| matching search results.
| page_token: Token specifying the next page of results. It should be obtained from
| a ``search_model_versions`` call.
|
| Returns:
| A PagedList of :py:class:`mlflow.entities.model_registry.ModelVersion`
| objects that satisfy the search expressions. The pagination token for the next
| page can be obtained via the ``token`` attribute of the object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Get all versions of the model filtered by name
| model_name = "CordobaWeatherForecastModel"
| filter_string = f"name='{model_name}'"
| results = client.search_model_versions(filter_string)
| print("-" * 80)
| for res in results:
| print(f"name={res.name}; run_id={res.run_id}; version={res.version}")
|
| # Get the version of the model filtered by run_id
| run_id = "e14afa2f47a040728060c1699968fd43"
| filter_string = f"run_id='{run_id}'"
| results = client.search_model_versions(filter_string)
| print("-" * 80)
| for res in results:
| print(f"name={res.name}; run_id={res.run_id}; version={res.version}")
|
| .. code-block:: text
| :caption: Output
|
| ------------------------------------------------------------------------------------
| name=CordobaWeatherForecastModel; run_id=eaef868ee3d14d10b4299c4c81ba8814; version=1
| name=CordobaWeatherForecastModel; run_id=e14afa2f47a040728060c1699968fd43; version=2
| ------------------------------------------------------------------------------------
| name=CordobaWeatherForecastModel; run_id=e14afa2f47a040728060c1699968fd43; version=2
|
| search_prompt_versions(self, name: str, max_results: int | None = None, page_token: str | None = None)
| Search prompt versions for a given prompt name.
|
| Args:
| name: Name of the prompt to search versions for.
| max_results: Maximum number of versions to return.
| page_token: Token for pagination.
|
| Returns:
| A :py:class:`PagedList <mlflow.store.entities.PagedList>` of
| :py:class:`~mlflow.entities.model_registry.PromptVersion` objects.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| versions = client.search_prompt_versions("my_prompt", max_results=10)
| for version in versions:
| print(f"Version {version.version}: {version.template}")
|
| search_prompts(self, filter_string: str | None = None, max_results: int = 1000, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.model_registry.prompt.Prompt]
| Search for prompts in the MLflow Prompt Registry.
|
| This call returns prompt metadata for prompts that have been marked
| as prompts (i.e. tagged with `mlflow.prompt.is_prompt=true`). We can
| further restrict results via a standard registry filter expression.
|
| Args:
| filter_string (Optional[str]):
| An additional registry-search expression to apply (e.g.
| `"name LIKE 'my_prompt%'"`). For Unity Catalog registries, must include
| catalog and schema: "catalog = 'catalog_name' AND schema = 'schema_name'".
| max_results (int):
| The maximum number of prompts to return in one page. Defaults
| to `SEARCH_MAX_RESULTS_DEFAULT` (typically 1 000).
| page_token (Optional[str]):
| A pagination token from a previous `search_prompts` call; use this
| to retrieve the next page of results. Defaults to `None`.
|
| Returns:
| A pageable list of :py:class:`Prompt <mlflow.entities.Prompt>` objects
| representing prompt metadata:
|
| - name: The prompt name
| - description: The prompt description
| - tags: Prompt-level tags
| - creation_timestamp: When the prompt was created
|
| To get the actual prompt template content,
| use get_prompt_version() with a specific version:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| # Your prompt registry URI
| client = MlflowClient(registry_uri="sqlite:///prompt_registry.db")
|
| # Search for prompts
| prompts = client.search_prompts(filter_string="name LIKE 'greeting%'")
|
| # Get prompts by experiment
| prompts = client.search_prompts(filter_string='experiment_id = "1"')
|
| # Get specific version content
| for prompt in prompts:
| prompt_version = client.get_prompt_version(prompt.name, version="1")
| print(f"Template: {prompt_version.template}")
|
| Inspect the returned object's `.token` attribute to fetch subsequent pages.
|
| search_registered_models(self, filter_string: str | None = None, max_results: int = 100, order_by: list[str] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.model_registry.registered_model.RegisteredModel]
| Search for registered models in backend that satisfy the filter criteria.
|
| Args:
| filter_string: Filter query string (e.g., "name = 'a_model_name' and tag.key =
| 'value1'"), defaults to searching for all registered models. The following
| identifiers, comparators, and logical operators are supported.
|
| Identifiers
| - ``name``: registered model name.
| - ``tags.<tag_key>``: registered model tag. If ``tag_key`` contains spaces, it
| must be wrapped with backticks (e.g., "tags.`extra key`").
|
| Comparators
| - ``=``: Equal to.
| - ``!=``: Not equal to.
| - ``LIKE``: Case-sensitive pattern match.
| - ``ILIKE``: Case-insensitive pattern match.
|
| Logical operators
| - ``AND``: Combines two sub-queries and returns True if both of them are True.
|
| max_results: Maximum number of registered models desired.
| order_by: List of column names with ASC|DESC annotation, to be used for ordering
| matching search results.
| page_token: Token specifying the next page of results. It should be obtained from
| a ``search_registered_models`` call.
|
| Returns:
| A PagedList of :py:class:`mlflow.entities.model_registry.RegisteredModel` objects
| that satisfy the search expressions. The pagination token for the next page can be
| obtained via the ``token`` attribute of the object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Get search results filtered by the registered model name
| model_name = "CordobaWeatherForecastModel"
| filter_string = f"name='{model_name}'"
| results = client.search_registered_models(filter_string=filter_string)
| print("-" * 80)
| for res in results:
| for mv in res.latest_versions:
| print(f"name={mv.name}; run_id={mv.run_id}; version={mv.version}")
|
| # Get search results filtered by the registered model name that matches
| # prefix pattern
| filter_string = "name LIKE 'Boston%'"
| results = client.search_registered_models(filter_string=filter_string)
| print("-" * 80)
| for res in results:
| for mv in res.latest_versions:
| print(f"name={mv.name}; run_id={mv.run_id}; version={mv.version}")
|
| # Get all registered models and order them by ascending order of the names
| results = client.search_registered_models(order_by=["name ASC"])
| print("-" * 80)
| for res in results:
| for mv in res.latest_versions:
| print(f"name={mv.name}; run_id={mv.run_id}; version={mv.version}")
|
| .. code-block:: text
| :caption: Output
|
| ------------------------------------------------------------------------------------
| name=CordobaWeatherForecastModel; run_id=eaef868ee3d14d10b4299c4c81ba8814; version=1
| name=CordobaWeatherForecastModel; run_id=e14afa2f47a040728060c1699968fd43; version=2
| ------------------------------------------------------------------------------------
| name=BostonWeatherForecastModel; run_id=ddc51b9407a54b2bb795c8d680e63ff6; version=1
| name=BostonWeatherForecastModel; run_id=48ac94350fba40639a993e1b3d4c185d; version=2
| -----------------------------------------------------------------------------------
| name=AzureWeatherForecastModel; run_id=5fcec6c4f1c947fc9295fef3fa21e52d; version=1
| name=AzureWeatherForecastModel; run_id=8198cb997692417abcdeb62e99052260; version=3
| name=BostonWeatherForecastModel; run_id=ddc51b9407a54b2bb795c8d680e63ff6; version=1
| name=BostonWeatherForecastModel; run_id=48ac94350fba40639a993e1b3d4c185d; version=2
| name=CordobaWeatherForecastModel; run_id=eaef868ee3d14d10b4299c4c81ba8814; version=1
| name=CordobaWeatherForecastModel; run_id=e14afa2f47a040728060c1699968fd43; version=2
|
| search_runs(self, experiment_ids: list[str], filter_string: str = '', run_view_type: int = 1, max_results: int = 1000, order_by: list[str] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.run.Run]
| Search for Runs that fit the specified criteria.
|
| Args:
| experiment_ids: List of experiment IDs, or a single int or string id.
| filter_string: Filter query string, defaults to searching all runs.
| run_view_type: one of enum values ACTIVE_ONLY, DELETED_ONLY, or ALL runs
| defined in :py:class:`mlflow.entities.ViewType`.
| max_results: Maximum number of runs desired.
| order_by: List of columns to order by (e.g., "metrics.rmse"). The ``order_by`` column
| can contain an optional ``DESC`` or ``ASC`` value. The default is ``ASC``.
| The default ordering is to sort by ``start_time DESC``, then ``run_id``.
| page_token: Token specifying the next page of results. It should be obtained from
| a ``search_runs`` call.
|
| Returns:
| A :py:class:`PagedList <mlflow.store.entities.PagedList>` of
| :py:class:`Run <mlflow.entities.Run>` objects that satisfy the search expressions.
| If the underlying tracking store supports pagination, the token for the next page may
| be obtained via the ``token`` attribute of the returned object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
| from mlflow.entities import ViewType
|
|
| def print_run_info(runs):
| for r in runs:
| print(f"run_id: {r.info.run_id}")
| print(f"lifecycle_stage: {r.info.lifecycle_stage}")
| print(f"metrics: {r.data.metrics}")
| # Exclude mlflow system tags
| tags = {k: v for k, v in r.data.tags.items() if not k.startswith("mlflow.")}
| print(f"tags: {tags}")
|
|
| # Create an experiment and log two runs with metrics and tags under the experiment
| experiment_id = mlflow.create_experiment("Social NLP Experiments")
| with mlflow.start_run(experiment_id=experiment_id) as run:
| mlflow.log_metric("m", 1.55)
| mlflow.set_tag("s.release", "1.1.0-RC")
| with mlflow.start_run(experiment_id=experiment_id):
| mlflow.log_metric("m", 2.50)
| mlflow.set_tag("s.release", "1.2.0-GA")
| # Search all runs under experiment id and order them by
| # descending value of the metric 'm'
| client = MlflowClient()
| runs = client.search_runs(experiment_id, order_by=["metrics.m DESC"])
| print_run_info(runs)
| print("--")
| # Delete the first run
| client.delete_run(run_id=run.info.run_id)
| # Search only deleted runs under the experiment id and use a case insensitive pattern
| # in the filter_string for the tag.
| filter_string = "tags.s.release ILIKE '%rc%'"
| runs = client.search_runs(
| experiment_id, run_view_type=ViewType.DELETED_ONLY, filter_string=filter_string
| )
| print_run_info(runs)
|
| .. code-block:: text
| :caption: Output
|
| run_id: 0efb2a68833d4ee7860a964fad31cb3f
| lifecycle_stage: active
| metrics: {'m': 2.5}
| tags: {'s.release': '1.2.0-GA'}
| run_id: 7ab027fd72ee4527a5ec5eafebb923b8
| lifecycle_stage: active
| metrics: {'m': 1.55}
| tags: {'s.release': '1.1.0-RC'}
| --
| run_id: 7ab027fd72ee4527a5ec5eafebb923b8
| lifecycle_stage: deleted
| metrics: {'m': 1.55}
| tags: {'s.release': '1.1.0-RC'}
|
| search_traces(self, experiment_ids: list[str] | None = None, filter_string: str | None = None, max_results: int = 100, order_by: list[str] | None = None, page_token: str | None = None, run_id: str | None = None, include_spans: bool = True, model_id: str | None = None, locations: list[str] | None = None, flush: bool = False) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.trace.Trace]
| .. Note:: Parameter ``experiment_ids`` is deprecated. Use ``locations`` instead.
|
| Return traces that match the given list of search expressions within the experiments.
|
| Args:
| experiment_ids: List of experiment ids to scope the search.
| filter_string: A search filter string.
| max_results: Maximum number of traces desired.
| order_by: List of order_by clauses.
| page_token: Token specifying the next page of results. It should be obtained from
| a ``search_traces`` call.
| run_id: A run id to scope the search. When a trace is created under an active run,
| it will be associated with the run and you can filter on the run id to retrieve
| the trace.
| include_spans: If ``True``, include spans in the returned traces. Otherwise, only
| the trace metadata is returned, e.g., trace ID, start time, end time, etc,
| without any spans.
| model_id: If specified, return traces associated with the model ID.
| locations: A list of locations to search over. To search over experiments, provide
| a list of experiment IDs. To search over UC tables on databricks, provide
| a list of locations in the format `<catalog_name>.<schema_name>`.
| flush: If ``True``, flush any pending async trace writes before searching.
| Useful in tests or scripts to ensure all traces are visible. Default to ``False``.
|
| Returns:
| A :py:class:`PagedList <mlflow.store.entities.PagedList>` of
| :py:class:`Trace <mlflow.entities.Trace>` objects that satisfy the search
| expressions. If the underlying tracking store supports pagination, the token for the
| next page may be obtained via the ``token`` attribute of the returned object; however,
| some store implementations may not support pagination and thus the returned token would
| not be meaningful in such cases.
|
| set_dataset_tags(self, dataset_id: str, tags: dict[str, typing.Any]) -> None
| Set tags for a dataset.
|
| This implements an upsert operation - existing tags are merged with new tags.
| To remove a tag, set its value to None.
|
| Args:
| dataset_id: The ID of the dataset to update.
| tags: Dictionary of tags to update. Setting a value to None removes the tag.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Set tags for a dataset
| client.set_dataset_tags(
| dataset_id="dataset123",
| tags={
| "environment": "production",
| "version": "2.0",
| "deprecated": None, # This removes the 'deprecated' tag
| },
| )
|
| set_experiment_tag(self, experiment_id: str, key: str, value: Any) -> None
| Set a tag on the experiment with the specified ID. Value is converted to a string.
|
| Args:
| experiment_id: String ID of the experiment.
| key: Name of the tag.
| value: Tag value (converted to a string).
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| # Create an experiment and set its tag
| client = MlflowClient()
| experiment_id = client.create_experiment("Social Media NLP Experiments")
| client.set_experiment_tag(experiment_id, "nlp.framework", "Spark NLP")
|
| # Fetch experiment metadata information
| experiment = client.get_experiment(experiment_id)
| print(f"Name: {experiment.name}")
| print(f"Tags: {experiment.tags}")
|
| .. code-block:: text
|
| Name: Social Media NLP Experiments
| Tags: {'nlp.framework': 'Spark NLP'}
|
| set_logged_model_tags(self, model_id: str, tags: dict[str, typing.Any]) -> None
| Set tags on the specified logged model.
|
| Args:
| model_id: ID of the model.
| tags: Tags to set on the model.
|
| Returns:
| None
|
| set_mcp_server_alias(self, name: str, alias: str, version: str) -> None
|
| set_mcp_server_tag(self, name: str, key: str, value: str) -> None
|
| set_mcp_server_version_tag(self, name: str, version: str, key: str, value: str) -> None
|
| set_model_version_tag(self, name: str, version: str | None = None, key: str | None = None, value: Any = None, stage: str | None = None) -> None
| Set a tag for the model version.
| When stage is set, tag will be set for latest model version of the stage.
| Setting both version and stage parameter will result in error.
|
| Args:
| name: Registered model name.
| version: Registered model version.
| key: Tag key to log. key is required.
| value: Tag value to log. value is required.
| stage: Registered model stage.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_version_info(mv):
| print(f"Name: {mv.name}")
| print(f"Version: {mv.version}")
| print(f"Tags: {mv.tags}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a new version of the rfr model under the registered model name
| # and set a tag
| model_uri = f"runs:/{run.info.run_id}/sklearn-model"
| mv = client.create_model_version(name, model_uri, run.info.run_id)
| print_model_version_info(mv)
| print("--")
|
| # Tag using model version
| client.set_model_version_tag(name, mv.version, "t", "1")
|
| # Tag using model stage
| client.set_model_version_tag(name, key="t1", value="1", stage=mv.current_stage)
| mv = client.get_model_version(name, mv.version)
| print_model_version_info(mv)
|
| .. code-block:: text
| :caption: Output
|
| Name: RandomForestRegression
| Version: 1
| Tags: {}
| --
| Name: RandomForestRegression
| Version: 1
| Tags: {'t': '1', 't1': '1'}
|
| set_prompt_alias(self, name: str, alias: str, version: int) -> None
| Set an alias for a :py:class:`Prompt <mlflow.entities.Prompt>`.
|
| Args:
| name: The name of the prompt.
| alias: The alias to set for the prompt.
| version: The version of the prompt.
|
| set_prompt_tag(self, name: str, key: str, value: str) -> None
| Set a tag on a prompt.
|
| This method delegates directly to the store, providing full Unity Catalog support
| when used with Unity Catalog registries.
|
| Args:
| name: Name of the prompt.
| key: Tag key.
| value: Tag value.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| client.set_prompt_tag("my_prompt", "environment", "production")
|
| set_prompt_version_tag(self, name: str, version: str | int, key: str, value: str) -> None
| Set a tag on a specific prompt version.
|
| Args:
| name: The name of the prompt.
| version: The version number of the prompt.
| key: The tag key.
| value: The tag value.
|
| set_registered_model_alias(self, name: str, alias: str, version: str) -> None
| Set a registered model alias pointing to a model version.
|
| Args:
| name: Registered model name.
| alias: Name of the alias. Note that aliases of the format ``v<number>``, such as
| ``v9`` and ``v42``, are reserved and cannot be set.
| version: Registered model version number.
|
| .. code-block:: Python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_info(rm):
| print("--Model--")
| print("name: {}".format(rm.name))
| print("aliases: {}".format(rm.aliases))
|
|
| def print_model_version_info(mv):
| print("--Model Version--")
| print("Name: {}".format(mv.name))
| print("Version: {}".format(mv.version))
| print("Aliases: {}".format(mv.aliases))
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, artifact_path="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
| model = client.get_registered_model(name)
| print_model_info(model)
|
| # Create a new version of the rfr model under the registered model name
| model_uri = "runs:/{}/sklearn-model".format(run.info.run_id)
| mv = client.create_model_version(name, model_uri, run.info.run_id)
| print_model_version_info(mv)
|
| # Set registered model alias
| client.set_registered_model_alias(name, "test-alias", mv.version)
| print()
| print_model_info(model)
| print_model_version_info(mv)
|
| .. code-block:: text
| :caption: Output
|
| --Model--
| name: RandomForestRegression
| aliases: {}
|
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: []
|
| --Model--
| name: RandomForestRegression
| aliases: {"test-alias": "1"}
|
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: ["test-alias"]
|
| set_registered_model_tag(self, name, key, value) -> None
| Set a tag for the registered model.
|
| Args:
| name: Registered model name.
| key: Tag key to log.
| value: Tag value log.
|
| .. code-block:: Python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
|
| def print_model_info(rm):
| print("--")
| print("name: {}".format(rm.name))
| print("tags: {}".format(rm.tags))
|
|
| name = "SocialMediaTextAnalyzer"
| tags = {"nlp.framework1": "Spark NLP"}
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| client = MlflowClient()
|
| # Create registered model, set an additional tag, and fetch
| # update model info
| client.create_registered_model(name, tags, desc)
| model = client.get_registered_model(name)
| print_model_info(model)
| client.set_registered_model_tag(name, "nlp.framework2", "VADER")
| model = client.get_registered_model(name)
| print_model_info(model)
|
| .. code-block:: text
| :caption: Output
|
| --
| name: SocialMediaTextAnalyzer
| tags: {'nlp.framework1': 'Spark NLP'}
| --
| name: SocialMediaTextAnalyzer
| tags: {'nlp.framework1': 'Spark NLP', 'nlp.framework2': 'VADER'}
|
| set_tag(self, run_id: str, key: str, value: Any, synchronous: bool | None = None) -> mlflow.utils.async_logging.run_operations.RunOperations | None
| Set a tag on the run with the specified ID. Value is converted to a string.
|
| Args:
| run_id: String ID of the run.
| key: Tag name. This string may only contain alphanumerics, underscores (_), dashes (-),
| periods (.), spaces ( ), and slashes (/). All backend stores will support keys up to
| length 250, but some may support larger keys.
| value: Tag value, but will be string-ified if not. All backend stores will support
| values up to length 5000, but some may support larger values.
| synchronous: *Experimental* If True, blocks until the metric is logged successfully.
| If False, logs the metric asynchronously and returns a future representing the
| logging operation. If None, read from environment variable
| `MLFLOW_ENABLE_ASYNC_LOGGING`, which defaults to False if not set.
|
| Returns:
| When `synchronous=True` or None, returns None. When `synchronous=False`, returns an
| `mlflow.utils.async_logging.run_operations.RunOperations` instance that represents
| future for logging operation.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_run_info(run):
| print(f"run_id: {run.info.run_id}")
| print(f"Tags: {run.data.tags}")
|
|
| # Create a run under the default experiment (whose id is '0').
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| print_run_info(run)
| print("--")
| # Set a tag and fetch updated run info
| client.set_tag(run.info.run_id, "nlp.framework", "Spark NLP")
| run = client.get_run(run.info.run_id)
| print_run_info(run)
|
| .. code-block:: text
| :caption: Output
|
| run_id: 4f226eb5758145e9b28f78514b59a03b
| Tags: {}
| --
| run_id: 4f226eb5758145e9b28f78514b59a03b
| Tags: {'nlp.framework': 'Spark NLP'}
|
| set_terminated(self, run_id: str, status: str | None = None, end_time: int | None = None) -> None
| Set a run's status to terminated.
|
| Args:
| run_id: The ID of the run to terminate.
| status: A string value of :py:class:`mlflow.entities.RunStatus`. Defaults to "FINISHED".
| end_time: If not provided, defaults to the current time.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
|
| def print_run_info(r):
| print(f"run_id: {r.info.run_id}")
| print(f"status: {r.info.status}")
|
|
| # Create a run under the default experiment (whose id is '0').
| # Since this is low-level CRUD operation, this method will create a run.
| # To end the run, you'll have to explicitly terminate it.
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| print_run_info(run)
| print("--")
|
| # Terminate the run and fetch updated status. By default,
| # the status is set to "FINISHED". Other values you can
| # set are "KILLED", "FAILED", "RUNNING", or "SCHEDULED".
| client.set_terminated(run.info.run_id, status="KILLED")
| run = client.get_run(run.info.run_id)
| print_run_info(run)
|
| .. code-block:: text
|
| run_id: 575fb62af83f469e84806aee24945973
| status: RUNNING
| --
| run_id: 575fb62af83f469e84806aee24945973
| status: KILLED
|
| set_trace_tag(self, trace_id: str, key: str, value: str)
| .. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
|
| Set a tag on the trace with the given trace ID.
|
| The trace can be an active one or the one that has already ended and recorded in the
| backend. Below is an example of setting a tag on an active trace. You can replace the
| ``trace_id`` parameter to set a tag on an already ended trace.
|
| .. code-block:: python
| :test:
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| root_span = client.start_trace("my_trace")
| client.set_trace_tag(root_span.trace_id, "key", "value")
| client.end_trace(root_span.trace_id)
|
| Args:
| trace_id: The ID of the trace to set the tag on.
| key: The string key of the tag. Must be at most 250 characters long, otherwise
| it will be truncated when stored.
| value: The string value of the tag. Must be at most 250 characters long, otherwise
| it will be truncated when stored.
|
| start_span(self, name: str, trace_id: str, parent_id: str, span_type: str = 'UNKNOWN', inputs: typing.Any | None = None, attributes: dict[str, typing.Any] | None = None, start_time_ns: int | None = None, links: list[mlflow.entities.link.Link] | None = None) -> mlflow.entities.span.Span
| .. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
|
| Create a new span and start it without attaching it to the global trace context.
|
| This is an imperative API to manually create a new span under a specific trace id
| and parent span, unlike the higher-level APIs like
| :py:func:`@mlflow.trace <mlflow.trace>` decorator and
| :py:func:`with mlflow.start_span() <mlflow.start_span>` context manager, which
| automatically manage the span lifecycle and parent-child relationship.
|
| This API is useful for the case where the automatic context management is not
| sufficient, such as callback-based instrumentation where span start and end are
| not in the same call stack, or multi-threaded applications where the context is
| not propagated automatically.
|
| This API requires a parent span ID to be provided explicitly. If you haven't
| started any span yet, use the :py:func:`start_trace() <start_trace>` method to
| start a new trace and a root span.
|
| .. warning::
|
| The span created with this method needs to be ended explicitly by calling
| the :py:func:`end_span() <end_span>` method. Otherwise the span will be
| recorded with the incorrect end time and status ``TRACE_STATUS_UNSPECIFIED``.
|
| .. tip::
|
| Instead of creating a root span with the :py:func:`start_trace() <start_trace>`
| method, you can also use this method within the context of a parent span created
| by the fluent APIs like :py:func:`@mlflow.trace <mlflow.trace>` and
| :py:func:`with mlflow.start_span() <mlflow.start_span>`, by passing its span
| ids the parent. This flexibility allows you to use the imperative APIs in
| conjunction with the fluent APIs like below:
|
| .. code-block:: python
| :test:
|
| import mlflow
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| with mlflow.start_span("parent_span") as parent_span:
| child_span = client.start_span(
| name="child_span",
| trace_id=parent_span.trace_id,
| parent_id=parent_span.span_id,
| )
|
| # Do something...
|
| client.end_span(
| trace_id=parent_span.trace_id,
| span_id=child_span.span_id,
| )
|
| However, **the opposite does not work**. You cannot use the fluent APIs within
| the span created by this MlflowClient API. This is because the fluent APIs
| fetches the current span from the managed context, which is not set by the MLflow
| Client APIs. Once you create a span with the MLflow Client APIs, all children
| spans must be created with the MLflow Client APIs. Please be cautious when using
| this mixed approach, as it can lead to unexpected behavior if not used properly.
|
| Args:
| name: The name of the span.
| trace_id: The ID of the trace to attach the span to. This is synonym to
| trace_id` in OpenTelemetry.
| parent_id: The ID of the parent span. The parent span can be a span created by
| both fluent APIs like `with mlflow.start_span()`, and imperative APIs like this.
| span_type: The type of the span. Can be either a string or a
| :py:class:`SpanType <mlflow.entities.SpanType>` enum value.
| inputs: Inputs to set on the span.
| attributes: A dictionary of attributes to set on the span.
| start_time_ns: The start time of the span in nano seconds since the UNIX epoch.
| If not provided, the current time will be used.
| links: A list of :py:class:`Link <mlflow.entities.Link>` objects to associate with
| the span.
|
| Returns:
| An :py:class:`mlflow.entities.Span` object representing the span.
|
| Example:
|
| .. code-block:: python
| :test:
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| span = client.start_trace("my_trace")
|
| x = 2
|
| # Create a child span
| child_span = client.start_span(
| "child_span",
| trace_id=span.trace_id,
| parent_id=span.span_id,
| inputs={"x": x},
| )
|
| y = x**2
|
| client.end_span(
| trace_id=child_span.trace_id,
| span_id=child_span.span_id,
| attributes={"factor": 2},
| outputs={"y": y},
| )
|
| client.end_trace(span.trace_id)
|
| start_trace(self, name: str, span_type: str = 'UNKNOWN', inputs: typing.Any | None = None, attributes: dict[str, str] | None = None, tags: dict[str, str] | None = None, experiment_id: str | None = None, start_time_ns: int | None = None, run_id: str | None = None, links: list[mlflow.entities.link.Link] | None = None) -> mlflow.entities.span.Span
| Create a new trace object and start a root span under it.
|
| This is an imperative API to manually create a new span under a specific trace id and
| parent span, unlike the higher-level APIs like :py:func:`@mlflow.trace <mlflow.trace>`
| and :py:func:`with mlflow.start_span() <mlflow.start_span>`, which automatically manage
| the span lifecycle and parent-child relationship. You only need to call this method
| when using the :py:func:`start_span() <start_span>` method of MlflowClient to create
| spans.
|
| .. attention::
|
| A trace started with this method must be ended by calling
| ``MlflowClient().end_trace(trace_id)``. Otherwise the trace will be not recorded.
|
| Args:
| name: The name of the trace (and the root span).
| span_type: The type of the span.
| inputs: Inputs to set on the root span of the trace.
| attributes: A dictionary of attributes to set on the root span of the trace.
| tags: A dictionary of tags to set on the trace.
| experiment_id: The ID of the experiment to create the trace in. If not provided,
| MLflow will look for valid experiment in the following order: activated using
| :py:func:`mlflow.set_experiment() <mlflow.set_experiment>`,
| ``MLFLOW_EXPERIMENT_NAME`` environment variable, ``MLFLOW_EXPERIMENT_ID``
| environment variable, or the default experiment as defined by the tracking server.
| start_time_ns: The start time of the trace in nanoseconds since the UNIX epoch.
| run_id: The ID of the MLflow run to associate with the trace. If provided, the
| trace will be linked to this run.
| links: A list of :py:class:`Link <mlflow.entities.Link>` objects to associate with
| the root span.
|
| Returns:
| An :py:class:`Span <mlflow.entities.Span>` object
| representing the root span of the trace.
|
| Example:
|
| .. code-block:: python
| :test:
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| root_span = client.start_trace("my_trace")
| trace_id = root_span.trace_id
|
| # Create a child span
| child_span = client.start_span(
| "child_span", trace_id=trace_id, parent_id=root_span.span_id
| )
| # Do something...
| client.end_span(trace_id=trace_id, span_id=child_span.span_id)
|
| client.end_trace(trace_id)
|
| test_webhook(self, webhook_id: str, event: Union[Literal['registered_model.created', 'model_version.created', 'model_version_tag.set', 'model_version_tag.deleted', 'model_version_alias.created', 'model_version_alias.deleted', 'prompt.created', 'prompt_version.created', 'prompt_tag.set', 'prompt_tag.deleted', 'prompt_version_tag.set', 'prompt_version_tag.deleted', 'prompt_alias.created', 'prompt_alias.deleted', 'budget_policy.exceeded'], mlflow.entities.webhook.WebhookEvent, NoneType] = None) -> mlflow.entities.webhook.WebhookTestResult
| Test a webhook by sending a test payload.
|
| Args:
| webhook_id: Webhook ID to test.
| event: Optional event type to test. Can be a WebhookEvent object or a string in
| "entity.action" format (e.g., "model_version.created"). If not specified, uses
| the first event from webhook.
|
| Returns:
| WebhookTestResult indicating success/failure and response details.
|
| transition_model_version_stage(self, name: str, version: str, stage: str, archive_existing_versions: bool = False) -> mlflow.entities.model_registry.model_version.ModelVersion
| .. Warning:: ``mlflow.tracking.client.MlflowClient.transition_model_version_stage`` is deprecated since 2.9.0. Model registry stages will be removed in a future major release. To learn more about the deprecation of model registry stages, see our migration guide here: https://mlflow.org/docs/latest/model-registry.html#migrating-from-stages
|
| Update model version stage.
|
| Args:
| name: Registered model name.
| version: Registered model version.
| stage: New desired stage for this model version.
| archive_existing_versions: If this flag is set to ``True``, all existing model
| versions in the stage will be automatically moved to the "archived" stage. Only
| valid when ``stage`` is ``"staging"`` or ``"production"`` otherwise an error will be
| raised.
|
| Returns:
| A single :py:class:`mlflow.entities.model_registry.ModelVersion` object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_version_info(mv):
| print(f"Name: {mv.name}")
| print(f"Version: {mv.version}")
| print(f"Description: {mv.description}")
| print(f"Stage: {mv.current_stage}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| desc = "A new version of the model using ensemble trees"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a new version of the rfr model under the registered model name
| model_uri = f"runs:/{run.info.run_id}/sklearn-model"
| mv = client.create_model_version(name, model_uri, run.info.run_id, description=desc)
| print_model_version_info(mv)
| print("--")
| # transition model version from None -> staging
| mv = client.transition_model_version_stage(name, mv.version, "staging")
| print_model_version_info(mv)
|
| .. code-block:: text
| :caption: Output
|
| Name: RandomForestRegression
| Version: 1
| Description: A new version of the model using ensemble trees
| Stage: None
| --
| Name: RandomForestRegression
| Version: 1
| Description: A new version of the model using ensemble trees
| Stage: Staging
|
| unlink_traces_from_run(self, trace_ids: list[str], run_id: str) -> None
| Unlink multiple traces from a run by removing entity associations.
|
| Args:
| trace_ids: List of trace IDs to unlink from the run.
| run_id: ID of the run to unlink traces from.
|
| Example:
| .. code-block:: python
|
| import mlflow
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Unlink multiple V4 traces from a run
| client.unlink_traces_from_run(
| trace_ids=[
| "trace://catalog.schema/abc123",
| "trace://catalog.schema/def456",
| ],
| run_id="run_abc",
| )
|
| update_mcp_access_endpoint(self, server_name: str, endpoint_id: str, url: str | None = <object object at 0x0000025F348EA210>, transport_type: mlflow.entities.mcp_server.MCPRemoteTransportType | None = <object object at 0x0000025F348EA210>, server_version: str | None = <object object at 0x0000025F348EA210>, server_alias: str | None = <object object at 0x0000025F348EA210>) -> mlflow.entities.mcp_access_endpoint.MCPAccessEndpoint
|
| update_mcp_server(self, name: str, display_name: str | None = <object object at 0x0000025F348EA210>, description: str | None = <object object at 0x0000025F348EA210>, icons: list[mlflow.store.tracking.mcp_server_registry.abstract_mixin.MCPIcon] | None = <object object at 0x0000025F348EA210>) -> mlflow.entities.mcp_server.MCPServer
|
| update_mcp_server_version(self, name: str, version: str, status: mlflow.entities.mcp_server.MCPStatus | None = <object object at 0x0000025F348EA210>, tools: list[mlflow.entities.mcp_server.MCPTool] | None = <object object at 0x0000025F348EA210>, connect_options: dict[str, mlflow.entities.mcp_server_version.ConnectOptionSettings] | None = <object object at 0x0000025F348EA210>) -> mlflow.entities.mcp_server_version.MCPServerVersion
|
| update_model_version(self, name: str, version: str, description: str | None = None) -> mlflow.entities.model_registry.model_version.ModelVersion
| Update metadata associated with a model version in backend.
|
| Args:
| name: Name of the containing registered model.
| version: Version number of the model version.
| description: New description.
|
| Returns:
| A single :py:class:`mlflow.entities.model_registry.ModelVersion` object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_version_info(mv):
| print(f"Name: {mv.name}")
| print(f"Version: {mv.version}")
| print(f"Description: {mv.description}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
| # Create a new version of the rfr model under the registered model name
| model_uri = f"runs:/{run.info.run_id}/sklearn-model"
| mv = client.create_model_version(name, model_uri, run.info.run_id)
| print_model_version_info(mv)
| print("--")
| # Update model version's description
| desc = "A new version of the model using ensemble trees"
| mv = client.update_model_version(name, mv.version, desc)
| print_model_version_info(mv)
|
| .. code-block:: text
| :caption: Output
|
| Name: RandomForestRegression
| Version: 1
| Description: None
| --
| Name: RandomForestRegression
| Version: 1
| Description: A new version of the model using ensemble trees
|
| update_registered_model(self, name: str, description: str | None = None, deployment_job_id: str | None = None) -> mlflow.entities.model_registry.registered_model.RegisteredModel
| Updates metadata for RegisteredModel entity. Input field ``description`` should be non-None.
| Backend raises exception if a registered model with given name does not exist.
|
| Args:
| name: Name of the registered model to update.
| description: (Optional) New description.
| deployment_job_id: Optional deployment job ID.
|
| Returns:
| A single updated :py:class:`mlflow.entities.model_registry.RegisteredModel` object.
|
| .. code-block:: python
| :caption: Example
|
| def print_registered_model_info(rm):
| print(f"name: {rm.name}")
| print(f"tags: {rm.tags}")
| print(f"description: {rm.description}")
|
|
| name = "SocialMediaTextAnalyzer"
| tags = {"nlp.framework": "Spark NLP"}
| desc = "This sentiment analysis model classifies the tone-happy, sad, angry."
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| client = MlflowClient()
| client.create_registered_model(name, tags, desc)
| print_registered_model_info(client.get_registered_model(name))
| print("--")
|
| # Update the model's description
| desc = "This sentiment analysis model classifies tweets' tone: happy, sad, angry."
| client.update_registered_model(name, desc)
| print_registered_model_info(client.get_registered_model(name))
|
| .. code-block:: text
| :caption: Output
|
| name: SocialMediaTextAnalyzer
| tags: {'nlp.framework': 'Spark NLP'}
| description: This sentiment analysis model classifies the tone-happy, sad, angry.
| --
| name: SocialMediaTextAnalyzer
| tags: {'nlp.framework': 'Spark NLP'}
| description: This sentiment analysis model classifies tweets' tone: happy, sad, angry.
|
| update_run(self, run_id: str, status: str | None = None, name: str | None = None) -> None
| Update a run with the specified ID to a new status or name.
|
| Args:
| run_id: The ID of the Run to update.
| status: The new status of the run to set, if specified. At least one of ``status`` or
| ``name`` should be specified.
| name: The new name of the run to set, if specified. At least one of ``name`` or
| ``status`` should be specified.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_run_info(run):
| print(f"run_id: {run.info.run_id}")
| print(f"run_name: {run.info.run_name}")
| print(f"status: {run.info.status}")
|
|
| # Create a run under the default experiment (whose id is '0').
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| print_run_info(run)
| print("--")
|
| # Update run and fetch info
| client.update_run(run.info.run_id, "FINISHED", "new_name")
| run = client.get_run(run.info.run_id)
| print_run_info(run)
|
| .. code-block:: text
| :caption: Output
|
| run_id: 1cf6bf8bf6484dd8a598bd43be367b20
| run_name: judicious-hog-915
| status: RUNNING
| --
| run_id: 1cf6bf8bf6484dd8a598bd43be367b20
| run_name: new_name
| status: FINISHED
|
| update_webhook(self, webhook_id: str, name: str | None = None, description: str | None = None, url: str | None = None, events: list[typing.Union[typing.Literal['registered_model.created', 'model_version.created', 'model_version_tag.set', 'model_version_tag.deleted', 'model_version_alias.created', 'model_version_alias.deleted', 'prompt.created', 'prompt_version.created', 'prompt_tag.set', 'prompt_tag.deleted', 'prompt_version_tag.set', 'prompt_version_tag.deleted', 'prompt_alias.created', 'prompt_alias.deleted', 'budget_policy.exceeded'], mlflow.entities.webhook.WebhookEvent]] | None = None, secret: str | None = None, status: str | mlflow.entities.webhook.WebhookStatus | None = None) -> mlflow.entities.webhook.Webhook
| Update an existing webhook.
|
| Args:
| webhook_id: Webhook ID.
| name: New webhook name.
| description: New webhook description.
| url: New webhook URL.
| events: New list of events. Can be strings or `WebhookEvent` objects.
| secret: New webhook secret.
| status: New webhook status. Can be string or WebhookStatus enum.
| Valid statuses: "ACTIVE", "DISABLED"
|
| Returns:
| A :py:class:`mlflow.entities.webhook.Webhook` object representing the updated webhook.
|
| update_workspace(self, name: str, description: str | None = None, default_artifact_root: str | None = None, trace_archival_config: mlflow.entities.workspace.TraceArchivalConfig | None = None) -> mlflow.entities.workspace.Workspace
| Update metadata for an existing workspace.
|
| Args:
| name: The name of the workspace to update.
| description: New description, or ``None`` to leave unchanged.
| default_artifact_root: New artifact root URI, empty string to clear, or ``None``.
| trace_archival_config: Optional Python-side grouping for trace archival settings.
| Use ``TraceArchivalConfig.location`` to update the archival storage URI/root and
| ``TraceArchivalConfig.retention`` to update the archived-trace retention duration
| such as ``30d`` or ``12h``. Use an empty string to clear an existing value, or
| leave fields as ``None`` to keep the current value unchanged.
|
| Returns:
| The updated workspace.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| tracking_uri
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
DATA
__all__ = ['MlflowClient']
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\client.py
mlflow.config
Python Library Documentation: package mlflow.config in mlflow
NAME
mlflow.config
PACKAGE CONTENTS
FUNCTIONS
disable_system_metrics_logging()
Disable system metrics logging globally.
Calling this function will disable system metrics logging globally, but users can still opt in
system metrics logging for individual runs by `mlflow.start_run(log_system_metrics=True)`.
enable_async_logging(enable=True)
Enable or disable async logging globally.
Args:
enable: bool, if True, enable async logging. If False, disable async logging.
.. code-block:: python
:caption: Example
import mlflow
mlflow.config.enable_async_logging(True)
with mlflow.start_run():
mlflow.log_param("a", 1) # This will be logged asynchronously
mlflow.config.enable_async_logging(False)
with mlflow.start_run():
mlflow.log_param("a", 1) # This will be logged synchronously
enable_system_metrics_logging()
Enable system metrics logging globally.
Calling this function will enable system metrics logging globally, but users can still opt out
system metrics logging for individual runs by `mlflow.start_run(log_system_metrics=False)`.
get_registry_uri() -> str
Get the current registry URI. If none has been specified, defaults to the tracking URI.
Returns:
The registry URI.
.. code-block:: python
# Get the current model registry uri
mr_uri = mlflow.get_registry_uri()
print(f"Current model registry uri: {mr_uri}")
# Get the current tracking uri
tracking_uri = mlflow.get_tracking_uri()
print(f"Current tracking uri: {tracking_uri}")
# They should be the same
assert mr_uri == tracking_uri
.. code-block:: text
Current model registry uri: file:///.../mlruns
Current tracking uri: file:///.../mlruns
get_tracking_uri() -> str
Get the current tracking URI. This may not correspond to the tracking URI of
the currently active run, since the tracking URI can be updated via ``set_tracking_uri``.
Returns:
The tracking URI.
.. code-block:: python
import mlflow
# Get the current tracking uri
tracking_uri = mlflow.get_tracking_uri()
print(f"Current tracking uri: {tracking_uri}")
.. code-block:: text
Current tracking uri: sqlite:///mlflow.db
is_tracking_uri_set()
Returns True if the tracking URI has been set, False otherwise.
set_registry_uri(uri: str) -> None
Set the registry server URI. This method is especially useful if you have a registry server
that's different from the tracking server.
Args:
uri: An empty string, or a local file path, prefixed with ``file:/``. Data is stored
locally at the provided file (or ``./mlruns`` if empty). An HTTP URI like
``https://my-tracking-server:5000`` or ``http://my-oss-uc-server:8080``. A Databricks
workspace, provided as the string "databricks" or, to use a Databricks CLI
`profile <https://github.com/databricks/databricks-cli#installation>`_,
"databricks://<profileName>".
.. code-block:: python
:caption: Example
import mflow
# Set model registry uri, fetch the set uri, and compare
# it with the tracking uri. They should be different
mlflow.set_registry_uri("sqlite:////tmp/registry.db")
mr_uri = mlflow.get_registry_uri()
print(f"Current registry uri: {mr_uri}")
tracking_uri = mlflow.get_tracking_uri()
print(f"Current tracking uri: {tracking_uri}")
# They should be different
assert tracking_uri != mr_uri
.. code-block:: text
:caption: Output
Current registry uri: sqlite:////tmp/registry.db
Current tracking uri: file:///.../mlruns
set_system_metrics_node_id(node_id)
Set the system metrics node id.
node_id is the identifier of the machine where the metrics are collected. This is useful in
multi-node (distributed training) setup.
set_system_metrics_samples_before_logging(samples)
Set the number of samples before logging system metrics.
Every time `samples` samples have been collected, the system metrics will be logged to mlflow.
By default `samples=1`.
set_system_metrics_sampling_interval(interval)
Set the system metrics sampling interval.
Every `interval` seconds, the system metrics will be collected. By default `interval=10`.
set_tracking_uri(uri: str | pathlib.Path) -> None
Set the tracking server URI. This does not affect the
currently active run (if one exists), but takes effect for successive runs.
Args:
uri:
- An empty string, or a local file path, prefixed with ``file:/``. Data is stored
locally at the provided file (or ``./mlruns`` if empty).
- An HTTP URI like ``https://my-tracking-server:5000``.
- A Databricks workspace, provided as the string "databricks" or, to use a Databricks
CLI `profile <https://github.com/databricks/databricks-cli#installation>`_,
"databricks://<profileName>".
- A :py:class:`pathlib.Path` instance
.. code-block:: python
:test:
:caption: Example
import mlflow
mlflow.set_tracking_uri("file:///tmp/my_tracking")
tracking_uri = mlflow.get_tracking_uri()
print(f"Current tracking uri: {tracking_uri}")
.. code-block:: text
:caption: Output
Current tracking uri: file:///tmp/my_tracking
DATA
__all__ = ['enable_system_metrics_logging', 'disable_system_metrics_lo...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\config\__init__.py
mlflow.context
Python Library Documentation: function context in module mlflow.tracing.context
context(metadata: 'dict[str, str] | None' = None, tags: 'dict[str, str] | None' = None, enabled: 'bool | None' = None, session_id: 'str | None' = None, user: 'str | None' = None) -> 'Generator[None, None, None]'
A context manager that injects metadata and/or tags into any trace created
within its scope, without creating a wrapper span. It can also be used to
selectively disable tracing within the scope.
This is useful when you need to attach trace-level information (e.g. session
IDs) to traces produced by code you don't control like auto-instrumented libraries,
or when you want to suppress tracing for a specific code block without affecting
the global tracing state.
.. code-block:: python
import mlflow
# Enable auto-tracing for LangChain
mlflow.langchain.autolog()
with mlflow.tracing.context(
session_id="session-123",
user="user-456",
tags={"project": "my-project"},
):
# Any trace created inside this block will carry the metadata and tags.
agent.invoke("What is the capital of France?")
# Disable tracing within a specific block
with mlflow.tracing.context(enabled=False):
# No traces will be created inside this block.
agent.invoke("This call will not be traced")
The context manager can be nested to combine multiple sets of metadata and tags. When same key
is specified in multiple levels, the value from the inner level takes precedence.
.. code-block:: python
import mlflow
with mlflow.tracing.context(metadata={"foo": "bar", "baz": "qux"}):
with mlflow.tracing.context(metadata={"foo": "baz", "qux": "quux"}):
my_func()
# Trace created by my_func will have metadata={"foo": "baz", "baz": "qux", "qux": "quux"}
Args:
metadata: Key-value pairs to inject into the trace's ``request_metadata``
(immutable after trace creation).
tags: Key-value pairs to inject into the trace's ``tags``.
enabled: Whether tracing is enabled within the scope. If ``False``, all
tracing calls within the scope will return ``NoOpSpan`` without creating
any traces. If ``None`` (default), the value is inherited from the outer
scope. This does not affect the global tracing state set by
:py:func:`mlflow.tracing.disable`.
session_id: Session ID to associate with traces created in this scope.
Internally stored as metadata under the ``mlflow.trace.session`` key.
user: User identifier to associate with traces created in this scope.
Internally stored as metadata under the ``mlflow.trace.user`` key.
mlflow.contextlib
Python Library Documentation: module contextlib
NAME
contextlib - Utilities for with-statement contexts. See PEP 343.
MODULE REFERENCE
https://docs.python.org/3.12/library/contextlib.html
The following documentation is automatically generated from the Python
source files. It may be incomplete, incorrect or include features that
are considered implementation detail and may vary between Python
implementations. When in doubt, consult the module reference at the
location listed above.
CLASSES
abc.ABC(builtins.object)
AbstractAsyncContextManager
AsyncExitStack(_BaseExitStack, AbstractAsyncContextManager)
aclosing
AbstractContextManager
ExitStack(_BaseExitStack, AbstractContextManager)
chdir
closing
nullcontext(AbstractContextManager, AbstractAsyncContextManager)
suppress
builtins.object
ContextDecorator
_BaseExitStack(builtins.object)
AsyncExitStack(_BaseExitStack, AbstractAsyncContextManager)
ExitStack(_BaseExitStack, AbstractContextManager)
_RedirectStream(AbstractContextManager)
redirect_stderr
redirect_stdout
class AbstractAsyncContextManager(abc.ABC)
| An abstract base class for asynchronous context managers.
|
| Method resolution order:
| AbstractAsyncContextManager
| abc.ABC
| builtins.object
|
| Methods defined here:
|
| async __aenter__(self)
| Return `self` upon entering the runtime context.
|
| async __aexit__(self, exc_type, exc_value, traceback)
| Raise any exception triggered within the runtime context.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __class_getitem__ = GenericAlias(...)
| Represent a PEP 585 generic type
|
| E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).
|
| __subclasshook__(C)
| Abstract classes can override this to customize issubclass().
|
| This is invoked early on by abc.ABCMeta.__subclasscheck__().
| It should return True, False or NotImplemented. If it returns
| NotImplemented, the normal algorithm is used. Otherwise, it
| overrides the normal algorithm (and the outcome is cached).
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset({'__aexit__'})
|
| __annotations__ = {}
class AbstractContextManager(abc.ABC)
| An abstract base class for context managers.
|
| Method resolution order:
| AbstractContextManager
| abc.ABC
| builtins.object
|
| Methods defined here:
|
| __enter__(self)
| Return `self` upon entering the runtime context.
|
| __exit__(self, exc_type, exc_value, traceback)
| Raise any exception triggered within the runtime context.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __class_getitem__ = GenericAlias(...)
| Represent a PEP 585 generic type
|
| E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).
|
| __subclasshook__(C)
| Abstract classes can override this to customize issubclass().
|
| This is invoked early on by abc.ABCMeta.__subclasscheck__().
| It should return True, False or NotImplemented. If it returns
| NotImplemented, the normal algorithm is used. Otherwise, it
| overrides the normal algorithm (and the outcome is cached).
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset({'__exit__'})
|
| __annotations__ = {}
class AsyncExitStack(_BaseExitStack, AbstractAsyncContextManager)
| Async context manager for dynamic management of a stack of exit
| callbacks.
|
| For example:
| async with AsyncExitStack() as stack:
| connections = [await stack.enter_async_context(get_connection())
| for i in range(5)]
| # All opened connections will automatically be released at the
| # end of the async with statement, even if attempts to open a
| # connection later in the list raise an exception.
|
| Method resolution order:
| AsyncExitStack
| _BaseExitStack
| AbstractAsyncContextManager
| abc.ABC
| builtins.object
|
| Methods defined here:
|
| async __aenter__(self)
| Return `self` upon entering the runtime context.
|
| async __aexit__(self, *exc_details)
| Raise any exception triggered within the runtime context.
|
| async aclose(self)
| Immediately unwind the context stack.
|
| async enter_async_context(self, cm)
| Enters the supplied async context manager.
|
| If successful, also pushes its __aexit__ method as a callback and
| returns the result of the __aenter__ method.
|
| push_async_callback(self, callback, /, *args, **kwds)
| Registers an arbitrary coroutine function and arguments.
|
| Cannot suppress exceptions.
|
| push_async_exit(self, exit)
| Registers a coroutine function with the standard __aexit__ method
| signature.
|
| Can suppress exceptions the same way __aexit__ method can.
| Also accepts any object with an __aexit__ method (registering a call
| to the method instead of the object itself).
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset()
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from _BaseExitStack:
|
| __init__(self)
| Initialize self. See help(type(self)) for accurate signature.
|
| callback(self, callback, /, *args, **kwds)
| Registers an arbitrary callback and arguments.
|
| Cannot suppress exceptions.
|
| enter_context(self, cm)
| Enters the supplied context manager.
|
| If successful, also pushes its __exit__ method as a callback and
| returns the result of the __enter__ method.
|
| pop_all(self)
| Preserve the context stack by transferring it to a new instance.
|
| push(self, exit)
| Registers a callback with the standard __exit__ method signature.
|
| Can suppress exceptions the same way __exit__ method can.
| Also accepts any object with an __exit__ method (registering a call
| to the method instead of the object itself).
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _BaseExitStack:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Class methods inherited from AbstractAsyncContextManager:
|
| __class_getitem__ = GenericAlias(...)
| Represent a PEP 585 generic type
|
| E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).
|
| __subclasshook__(C)
| Abstract classes can override this to customize issubclass().
|
| This is invoked early on by abc.ABCMeta.__subclasscheck__().
| It should return True, False or NotImplemented. If it returns
| NotImplemented, the normal algorithm is used. Otherwise, it
| overrides the normal algorithm (and the outcome is cached).
class ContextDecorator(builtins.object)
| A base class or mixin that enables context managers to work as decorators.
|
| Methods defined here:
|
| __call__(self, func)
| Call self as a function.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class ExitStack(_BaseExitStack, AbstractContextManager)
| Context manager for dynamic management of a stack of exit callbacks.
|
| For example:
| with ExitStack() as stack:
| files = [stack.enter_context(open(fname)) for fname in filenames]
| # All opened files will automatically be closed at the end of
| # the with statement, even if attempts to open files later
| # in the list raise an exception.
|
| Method resolution order:
| ExitStack
| _BaseExitStack
| AbstractContextManager
| abc.ABC
| builtins.object
|
| Methods defined here:
|
| __enter__(self)
| Return `self` upon entering the runtime context.
|
| __exit__(self, *exc_details)
| Raise any exception triggered within the runtime context.
|
| close(self)
| Immediately unwind the context stack.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset()
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from _BaseExitStack:
|
| __init__(self)
| Initialize self. See help(type(self)) for accurate signature.
|
| callback(self, callback, /, *args, **kwds)
| Registers an arbitrary callback and arguments.
|
| Cannot suppress exceptions.
|
| enter_context(self, cm)
| Enters the supplied context manager.
|
| If successful, also pushes its __exit__ method as a callback and
| returns the result of the __enter__ method.
|
| pop_all(self)
| Preserve the context stack by transferring it to a new instance.
|
| push(self, exit)
| Registers a callback with the standard __exit__ method signature.
|
| Can suppress exceptions the same way __exit__ method can.
| Also accepts any object with an __exit__ method (registering a call
| to the method instead of the object itself).
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _BaseExitStack:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Class methods inherited from AbstractContextManager:
|
| __class_getitem__ = GenericAlias(...)
| Represent a PEP 585 generic type
|
| E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).
|
| __subclasshook__(C)
| Abstract classes can override this to customize issubclass().
|
| This is invoked early on by abc.ABCMeta.__subclasscheck__().
| It should return True, False or NotImplemented. If it returns
| NotImplemented, the normal algorithm is used. Otherwise, it
| overrides the normal algorithm (and the outcome is cached).
class aclosing(AbstractAsyncContextManager)
| aclosing(thing)
|
| Async context manager for safely finalizing an asynchronously cleaned-up
| resource such as an async generator, calling its ``aclose()`` method.
|
| Code like this:
|
| async with aclosing(<module>.fetch(<arguments>)) as agen:
| <block>
|
| is equivalent to this:
|
| agen = <module>.fetch(<arguments>)
| try:
| <block>
| finally:
| await agen.aclose()
|
| Method resolution order:
| aclosing
| AbstractAsyncContextManager
| abc.ABC
| builtins.object
|
| Methods defined here:
|
| async __aenter__(self)
| Return `self` upon entering the runtime context.
|
| async __aexit__(self, *exc_info)
| Raise any exception triggered within the runtime context.
|
| __init__(self, thing)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset()
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Class methods inherited from AbstractAsyncContextManager:
|
| __class_getitem__ = GenericAlias(...)
| Represent a PEP 585 generic type
|
| E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).
|
| __subclasshook__(C)
| Abstract classes can override this to customize issubclass().
|
| This is invoked early on by abc.ABCMeta.__subclasscheck__().
| It should return True, False or NotImplemented. If it returns
| NotImplemented, the normal algorithm is used. Otherwise, it
| overrides the normal algorithm (and the outcome is cached).
|
| ----------------------------------------------------------------------
| Data descriptors inherited from AbstractAsyncContextManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class chdir(AbstractContextManager)
| chdir(path)
|
| Non thread-safe context manager to change the current working directory.
|
| Method resolution order:
| chdir
| AbstractContextManager
| abc.ABC
| builtins.object
|
| Methods defined here:
|
| __enter__(self)
| Return `self` upon entering the runtime context.
|
| __exit__(self, *excinfo)
| Raise any exception triggered within the runtime context.
|
| __init__(self, path)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset()
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Class methods inherited from AbstractContextManager:
|
| __class_getitem__ = GenericAlias(...)
| Represent a PEP 585 generic type
|
| E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).
|
| __subclasshook__(C)
| Abstract classes can override this to customize issubclass().
|
| This is invoked early on by abc.ABCMeta.__subclasscheck__().
| It should return True, False or NotImplemented. If it returns
| NotImplemented, the normal algorithm is used. Otherwise, it
| overrides the normal algorithm (and the outcome is cached).
|
| ----------------------------------------------------------------------
| Data descriptors inherited from AbstractContextManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class closing(AbstractContextManager)
| closing(thing)
|
| Context to automatically close something at the end of a block.
|
| Code like this:
|
| with closing(<module>.open(<arguments>)) as f:
| <block>
|
| is equivalent to this:
|
| f = <module>.open(<arguments>)
| try:
| <block>
| finally:
| f.close()
|
| Method resolution order:
| closing
| AbstractContextManager
| abc.ABC
| builtins.object
|
| Methods defined here:
|
| __enter__(self)
| Return `self` upon entering the runtime context.
|
| __exit__(self, *exc_info)
| Raise any exception triggered within the runtime context.
|
| __init__(self, thing)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset()
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Class methods inherited from AbstractContextManager:
|
| __class_getitem__ = GenericAlias(...)
| Represent a PEP 585 generic type
|
| E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).
|
| __subclasshook__(C)
| Abstract classes can override this to customize issubclass().
|
| This is invoked early on by abc.ABCMeta.__subclasscheck__().
| It should return True, False or NotImplemented. If it returns
| NotImplemented, the normal algorithm is used. Otherwise, it
| overrides the normal algorithm (and the outcome is cached).
|
| ----------------------------------------------------------------------
| Data descriptors inherited from AbstractContextManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class nullcontext(AbstractContextManager, AbstractAsyncContextManager)
| nullcontext(enter_result=None)
|
| Context manager that does no additional processing.
|
| Used as a stand-in for a normal context manager, when a particular
| block of code is only sometimes used with a normal context manager:
|
| cm = optional_cm if condition else nullcontext()
| with cm:
| # Perform operation, using optional_cm if condition is True
|
| Method resolution order:
| nullcontext
| AbstractContextManager
| AbstractAsyncContextManager
| abc.ABC
| builtins.object
|
| Methods defined here:
|
| async __aenter__(self)
| Return `self` upon entering the runtime context.
|
| async __aexit__(self, *excinfo)
| Raise any exception triggered within the runtime context.
|
| __enter__(self)
| Return `self` upon entering the runtime context.
|
| __exit__(self, *excinfo)
| Raise any exception triggered within the runtime context.
|
| __init__(self, enter_result=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset()
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Class methods inherited from AbstractContextManager:
|
| __class_getitem__ = GenericAlias(...)
| Represent a PEP 585 generic type
|
| E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).
|
| __subclasshook__(C)
| Abstract classes can override this to customize issubclass().
|
| This is invoked early on by abc.ABCMeta.__subclasscheck__().
| It should return True, False or NotImplemented. If it returns
| NotImplemented, the normal algorithm is used. Otherwise, it
| overrides the normal algorithm (and the outcome is cached).
|
| ----------------------------------------------------------------------
| Data descriptors inherited from AbstractContextManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class redirect_stderr(_RedirectStream)
| redirect_stderr(new_target)
|
| Context manager for temporarily redirecting stderr to another file.
|
| Method resolution order:
| redirect_stderr
| _RedirectStream
| AbstractContextManager
| abc.ABC
| builtins.object
|
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset()
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from _RedirectStream:
|
| __enter__(self)
| Return `self` upon entering the runtime context.
|
| __exit__(self, exctype, excinst, exctb)
| Raise any exception triggered within the runtime context.
|
| __init__(self, new_target)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Class methods inherited from AbstractContextManager:
|
| __class_getitem__ = GenericAlias(...)
| Represent a PEP 585 generic type
|
| E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).
|
| __subclasshook__(C)
| Abstract classes can override this to customize issubclass().
|
| This is invoked early on by abc.ABCMeta.__subclasscheck__().
| It should return True, False or NotImplemented. If it returns
| NotImplemented, the normal algorithm is used. Otherwise, it
| overrides the normal algorithm (and the outcome is cached).
|
| ----------------------------------------------------------------------
| Data descriptors inherited from AbstractContextManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class redirect_stdout(_RedirectStream)
| redirect_stdout(new_target)
|
| Context manager for temporarily redirecting stdout to another file.
|
| # How to send help() to stderr
| with redirect_stdout(sys.stderr):
| help(dir)
|
| # How to write help() to a file
| with open('help.txt', 'w') as f:
| with redirect_stdout(f):
| help(pow)
|
| Method resolution order:
| redirect_stdout
| _RedirectStream
| AbstractContextManager
| abc.ABC
| builtins.object
|
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset()
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from _RedirectStream:
|
| __enter__(self)
| Return `self` upon entering the runtime context.
|
| __exit__(self, exctype, excinst, exctb)
| Raise any exception triggered within the runtime context.
|
| __init__(self, new_target)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Class methods inherited from AbstractContextManager:
|
| __class_getitem__ = GenericAlias(...)
| Represent a PEP 585 generic type
|
| E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).
|
| __subclasshook__(C)
| Abstract classes can override this to customize issubclass().
|
| This is invoked early on by abc.ABCMeta.__subclasscheck__().
| It should return True, False or NotImplemented. If it returns
| NotImplemented, the normal algorithm is used. Otherwise, it
| overrides the normal algorithm (and the outcome is cached).
|
| ----------------------------------------------------------------------
| Data descriptors inherited from AbstractContextManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class suppress(AbstractContextManager)
| suppress(*exceptions)
|
| Context manager to suppress specified exceptions
|
| After the exception is suppressed, execution proceeds with the next
| statement following the with statement.
|
| with suppress(FileNotFoundError):
| os.remove(somefile)
| # Execution still resumes here if the file was already removed
|
| Method resolution order:
| suppress
| AbstractContextManager
| abc.ABC
| builtins.object
|
| Methods defined here:
|
| __enter__(self)
| Return `self` upon entering the runtime context.
|
| __exit__(self, exctype, excinst, exctb)
| Raise any exception triggered within the runtime context.
|
| __init__(self, *exceptions)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset()
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Class methods inherited from AbstractContextManager:
|
| __class_getitem__ = GenericAlias(...)
| Represent a PEP 585 generic type
|
| E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).
|
| __subclasshook__(C)
| Abstract classes can override this to customize issubclass().
|
| This is invoked early on by abc.ABCMeta.__subclasscheck__().
| It should return True, False or NotImplemented. If it returns
| NotImplemented, the normal algorithm is used. Otherwise, it
| overrides the normal algorithm (and the outcome is cached).
|
| ----------------------------------------------------------------------
| Data descriptors inherited from AbstractContextManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FUNCTIONS
asynccontextmanager(func)
@asynccontextmanager decorator.
Typical usage:
@asynccontextmanager
async def some_async_generator(<arguments>):
<setup>
try:
yield <value>
finally:
<cleanup>
This makes this:
async with some_async_generator(<arguments>) as <variable>:
<body>
equivalent to this:
<setup>
try:
<variable> = <value>
<body>
finally:
<cleanup>
contextmanager(func)
@contextmanager decorator.
Typical usage:
@contextmanager
def some_generator(<arguments>):
<setup>
try:
yield <value>
finally:
<cleanup>
This makes this:
with some_generator(<arguments>) as <variable>:
<body>
equivalent to this:
<setup>
try:
<variable> = <value>
<body>
finally:
<cleanup>
DATA
__all__ = ['asynccontextmanager', 'contextmanager', 'closing', 'nullco...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\contextlib.py
mlflow.create_experiment
Python Library Documentation: function create_experiment in module mlflow.tracking.fluent
create_experiment(name: str, artifact_location: str | None = None, tags: dict[str, typing.Any] | None = None, trace_location: mlflow.entities.trace_location.UnityCatalog | None = None) -> str
Create an experiment.
Args:
name: The experiment name, must be a non-empty unique string.
artifact_location: The location to store run artifacts. If not provided, the server picks
an appropriate default.
tags: An optional dictionary of string keys and values to set as tags on the experiment.
trace_location: Optional UC trace location to link to the experiment. Must be an instance
of ``mlflow.entities.trace_location.UnityCatalog(...)``. If ``table_prefix`` is not
set, it defaults to the experiment ID. Note: call ``mlflow.set_experiment`` afterward
to activate the experiment and sync the trace provider.
Returns:
String ID of the created experiment.
.. code-block:: python
:test:
:caption: Example
import mlflow
from pathlib import Path
# Create an experiment name, which must be unique and case sensitive
experiment_id = mlflow.create_experiment(
"Social NLP Experiments",
artifact_location=Path.cwd().joinpath("mlruns").as_uri(),
tags={"version": "v1", "priority": "P1"},
)
experiment = mlflow.get_experiment(experiment_id)
print(f"Name: {experiment.name}")
print(f"Experiment_id: {experiment.experiment_id}")
print(f"Artifact Location: {experiment.artifact_location}")
print(f"Tags: {experiment.tags}")
print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
print(f"Creation timestamp: {experiment.creation_time}")
.. code-block:: text
:caption: Output
Name: Social NLP Experiments
Experiment_id: 1
Artifact Location: file:///.../mlruns
Tags: {'version': 'v1', 'priority': 'P1'}
Lifecycle_stage: active
Creation timestamp: 1662004217511
mlflow.create_external_model
Python Library Documentation: function create_external_model in module mlflow.tracking.fluent
create_external_model(name: str | None = None, source_run_id: str | None = None, tags: dict[str, str] | None = None, params: dict[str, str] | None = None, model_type: str | None = None, experiment_id: str | None = None) -> mlflow.entities.logged_model.LoggedModel
Create a new LoggedModel whose artifacts are stored outside of MLflow. This is useful for
tracking parameters and performance data (metrics, traces etc.) for a model, application, or
generative AI agent that is not packaged using the MLflow Model format.
Args:
name: The name of the model. If not specified, a random name will be generated.
source_run_id: The ID of the run that the model is associated with. If unspecified and a
run is active, the active run ID will be used.
tags: A dictionary of string keys and values to set as tags on the model.
params: A dictionary of string keys and values to set as parameters on the model.
model_type: The type of the model. This is a user-defined string that can be used to
search and compare related models. For example, setting ``model_type="agent"``
enables you to easily search for this model and compare it to other models of
type ``"agent"`` in the future.
experiment_id: The experiment ID of the experiment to which the model belongs.
Returns:
A new :py:class:`mlflow.entities.LoggedModel` object with status ``READY``.
mlflow.create_workspace
Python Library Documentation: function create_workspace in module mlflow.tracking._workspace.fluent
create_workspace(name: 'str', description: 'str | None' = None, default_artifact_root: 'str | None' = None, trace_archival_config: 'TraceArchivalConfig | None' = None) -> 'Workspace'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Create a new workspace.
Args:
name: The workspace name (lowercase alphanumeric with optional internal hyphens).
description: Optional description of the workspace.
default_artifact_root: Optional artifact root URI; falls back to server default.
trace_archival_config: Optional archival settings; leave fields as ``None`` to omit them.
Returns:
The newly created workspace.
Raises:
MlflowException: If the name is invalid, already exists, or no artifact root available.
mlflow.crewai
Python Library Documentation: package mlflow.crewai in mlflow
NAME
mlflow.crewai - The ``mlflow.crewai`` module provides an API for tracing CrewAI AI agents.
PACKAGE CONTENTS
autolog
DATA
FLAVOR_NAME = 'crewai'
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\crewai\__init__.py
mlflow.data
Python Library Documentation: package mlflow.data in mlflow
NAME
mlflow.data
PACKAGE CONTENTS
artifact_dataset_sources
code_dataset_source
dataset
dataset_registry
dataset_source
dataset_source_registry
delta_dataset_source
digest_utils
evaluation_dataset
evaluation_dataset_source
filesystem_dataset_source
http_dataset_source
huggingface_dataset
huggingface_dataset_source
meta_dataset
numpy_dataset
pandas_dataset
polars_dataset
pyfunc_dataset_mixin
schema
sources
spark_dataset
spark_dataset_source
spark_delta_utils
tensorflow_dataset
uc_volume_dataset_source
SUBMODULES
mlflow_data_sources
FUNCTIONS
from_huggingface(ds, path: str | None = None, targets: str | None = None, data_dir: str | None = None, data_files: Union[str, Sequence[str], Mapping[str, Union[str, Sequence[str]]], NoneType] = None, revision=None, name: str | None = None, digest: str | None = None, trust_remote_code: bool | None = None, source: str | mlflow.data.dataset_source.DatasetSource | None = None) -> mlflow.data.huggingface_dataset.HuggingFaceDataset
Create a `mlflow.data.huggingface_dataset.HuggingFaceDataset` from a Hugging Face dataset.
Args:
ds:
A Hugging Face dataset. Must be an instance of `datasets.Dataset`. Other types, such as
`datasets.DatasetDict`, are not supported.
path: The path of the Hugging Face dataset used to construct the source. This is the same
argument as `path` in `datasets.load_dataset()` function. To be able to reload the
dataset via MLflow, `path` must match the path of the dataset on the hub, e.g.,
"databricks/databricks-dolly-15k". If no path is specified, a `CodeDatasetSource` is,
used which will source information from the run context.
targets: The name of the Hugging Face `dataset.Dataset` column containing targets (labels)
for supervised learning.
data_dir: The `data_dir` of the Hugging Face dataset configuration. This is used by the
`datasets.load_dataset()` function to reload the dataset upon request via
:py:func:`HuggingFaceDataset.source.load()
<mlflow.data.huggingface_dataset_source.HuggingFaceDatasetSource.load>`.
data_files: Paths to source data file(s) for the Hugging Face dataset configuration.
This is used by the `datasets.load_dataset()` function to reload the
dataset upon request via :py:func:`HuggingFaceDataset.source.load()
<mlflow.data.huggingface_dataset_source.HuggingFaceDatasetSource.load>`.
revision: Version of the dataset script to load. This is used by the
`datasets.load_dataset()` function to reload the dataset upon request via
:py:func:`HuggingFaceDataset.source.load()
<mlflow.data.huggingface_dataset_source.HuggingFaceDatasetSource.load>`.
name: The name of the dataset. E.g. "wiki_train". If unspecified, a name is automatically
generated.
digest: The digest (hash, fingerprint) of the dataset. If unspecified, a digest is
automatically computed.
trust_remote_code: Whether to trust remote code from the dataset repo.
source: The source of the dataset, e.g. a S3 URI, an HTTPS URL etc.
from_numpy(features: numpy.ndarray | dict[str, numpy.ndarray], source: str | mlflow.data.dataset_source.DatasetSource = None, targets: numpy.ndarray | dict[str, numpy.ndarray] = None, name: str | None = None, digest: str | None = None) -> mlflow.data.numpy_dataset.NumpyDataset
Constructs a :py:class:`NumpyDataset <mlflow.data.numpy_dataset.NumpyDataset>` object from
NumPy features, optional targets, and source. If the source is path like, then this will
construct a DatasetSource object from the source path. Otherwise, the source is assumed to
be a DatasetSource object.
Args:
features: NumPy features, represented as an np.ndarray or dictionary of named np.ndarrays.
source: The source from which the numpy data was derived, e.g. a filesystem path, an S3 URI,
an HTTPS URL, a delta table name with version, or spark table etc. ``source`` may be
specified as a URI, a path-like string, or an instance of
:py:class:`DatasetSource <mlflow.data.dataset_source.DatasetSource>`. If unspecified,
the source is assumed to be the code location (e.g. notebook cell, script, etc.) where
:py:func:`from_numpy <mlflow.data.from_numpy>` is being called.
targets: Optional NumPy targets, represented as an np.ndarray or dictionary of named
np.ndarrays.
name: The name of the dataset. If unspecified, a name is generated.
digest: The dataset digest (hash). If unspecified, a digest is computed automatically.
.. code-block:: python
:test:
:caption: Basic Example
import mlflow
import numpy as np
x = np.random.uniform(size=[2, 5, 4])
y = np.random.randint(2, size=[2])
dataset = mlflow.data.from_numpy(x, targets=y)
.. code-block:: python
:test:
:caption: Dict Example
import mlflow
import numpy as np
x = {
"feature_1": np.random.uniform(size=[2, 5, 4]),
"feature_2": np.random.uniform(size=[2, 5, 4]),
}
y = np.random.randint(2, size=[2])
dataset = mlflow.data.from_numpy(x, targets=y)
from_pandas(df: pandas.core.frame.DataFrame, source: str | mlflow.data.dataset_source.DatasetSource = None, targets: str | None = None, name: str | None = None, digest: str | None = None, predictions: str | None = None) -> mlflow.data.pandas_dataset.PandasDataset
Constructs a :py:class:`PandasDataset <mlflow.data.pandas_dataset.PandasDataset>` instance from
a Pandas DataFrame, optional targets, optional predictions, and source.
Args:
df: A Pandas DataFrame.
source: The source from which the DataFrame was derived, e.g. a filesystem
path, an S3 URI, an HTTPS URL, a delta table name with version, or
spark table etc. ``source`` may be specified as a URI, a path-like string,
or an instance of
:py:class:`DatasetSource <mlflow.data.dataset_source.DatasetSource>`.
If unspecified, the source is assumed to be the code location
(e.g. notebook cell, script, etc.) where
:py:func:`from_pandas <mlflow.data.from_pandas>` is being called.
targets: An optional target column name for supervised training. This column
must be present in the dataframe (``df``).
name: The name of the dataset. If unspecified, a name is generated.
digest: The dataset digest (hash). If unspecified, a digest is computed
automatically.
predictions: An optional predictions column name for model evaluation. This column
must be present in the dataframe (``df``).
.. code-block:: python
:test:
:caption: Example
import mlflow
import pandas as pd
x = pd.DataFrame(
[["tom", 10, 1, 1], ["nick", 15, 0, 1], ["july", 14, 1, 1]],
columns=["Name", "Age", "Label", "ModelOutput"],
)
dataset = mlflow.data.from_pandas(x, targets="Label", predictions="ModelOutput")
from_polars(df: polars.dataframe.frame.DataFrame, source: str | mlflow.data.dataset_source.DatasetSource | None = None, targets: str | None = None, name: str | None = None, digest: str | None = None, predictions: str | None = None) -> mlflow.data.polars_dataset.PolarsDataset
Construct a :py:class:`PolarsDataset <mlflow.data.polars_dataset.PolarsDataset>` instance.
Args:
df: A polars DataFrame.
source: Source from which the DataFrame was derived, e.g. a filesystem
path, an S3 URI, an HTTPS URL, a delta table name with version, or
spark table etc. ``source`` may be specified as a URI, a path-like string,
or an instance of
:py:class:`DatasetSource <mlflow.data.dataset_source.DatasetSource>`.
If unspecified, the source is assumed to be the code location
(e.g. notebook cell, script, etc.) where
:py:func:`from_polars <mlflow.data.from_polars>` is being called.
targets: An optional target column name for supervised training. This column
must be present in ``df``.
name: Name of the dataset. If unspecified, a name is generated.
digest: Dataset digest (hash). If unspecified, a digest is computed
automatically.
predictions: An optional predictions column name for model evaluation. This column
must be present in ``df``.
.. code-block:: python
:test:
:caption: Example
import mlflow
import polars as pl
x = pl.DataFrame(
[["tom", 10, 1, 1], ["nick", 15, 0, 1], ["julie", 14, 1, 1]],
schema=["Name", "Age", "Label", "ModelOutput"],
)
dataset = mlflow.data.from_polars(x, targets="Label", predictions="ModelOutput")
from_spark(df: 'pyspark.sql.DataFrame', path: str | None = None, table_name: str | None = None, version: str | None = None, sql: str | None = None, targets: str | None = None, name: str | None = None, digest: str | None = None, predictions: str | None = None) -> mlflow.data.spark_dataset.SparkDataset
Given a Spark DataFrame, constructs a
:py:class:`SparkDataset <mlflow.data.spark_dataset.SparkDataset>` object for use with
MLflow Tracking.
Args:
df: The Spark DataFrame from which to construct a SparkDataset.
path: The path of the Spark or Delta source that the DataFrame originally came from. Note
that the path does not have to match the DataFrame exactly, since the DataFrame may have
been modified by Spark operations. This is used to reload the dataset upon request via
:py:func:`SparkDataset.source.load()
<mlflow.data.spark_dataset_source.SparkDatasetSource.load>`. If none of ``path``,
``table_name``, or ``sql`` are specified, a CodeDatasetSource is used, which will source
information from the run context.
table_name: The name of the Spark or Delta table that the DataFrame originally came from.
Note that the table does not have to match the DataFrame exactly, since the DataFrame
may have been modified by Spark operations. This is used to reload the dataset upon
request via :py:func:`SparkDataset.source.load()
<mlflow.data.spark_dataset_source.SparkDatasetSource.load>`. If none of ``path``,
``table_name``, or ``sql`` are specified, a CodeDatasetSource is used, which will source
information from the run context.
version: If the DataFrame originally came from a Delta table, specifies the version of the
Delta table. This is used to reload the dataset upon request via
:py:func:`SparkDataset.source.load()
<mlflow.data.spark_dataset_source.SparkDatasetSource.load>`. ``version`` cannot be
specified if ``sql`` is specified.
sql: The Spark SQL statement that was originally used to construct the DataFrame. Note that
the Spark SQL statement does not have to match the DataFrame exactly, since the
DataFrame may have been modified by Spark operations. This is used to reload the dataset
upon request via :py:func:`SparkDataset.source.load()
<mlflow.data.spark_dataset_source.SparkDatasetSource.load>`. If none of ``path``,
``table_name``, or ``sql`` are specified, a CodeDatasetSource is used, which will source
information from the run context.
targets: Optional. The name of the Data Frame column containing targets (labels) for
supervised learning.
name: The name of the dataset. E.g. "wiki_train". If unspecified, a name is automatically
generated.
digest: The digest (hash, fingerprint) of the dataset. If unspecified, a digest is
automatically computed.
predictions: Optional. The name of the column containing model predictions,
if the dataset contains model predictions. If specified, this column
must be present in the dataframe (``df``).
Returns:
An instance of :py:class:`SparkDataset <mlflow.data.spark_dataset.SparkDataset>`.
from_tensorflow(features, source: str | mlflow.data.dataset_source.DatasetSource | None = None, targets=None, name: str | None = None, digest: str | None = None) -> mlflow.data.tensorflow_dataset.TensorFlowDataset
Constructs a TensorFlowDataset object from TensorFlow data, optional targets, and source.
If the source is path like, then this will construct a DatasetSource object from the source
path. Otherwise, the source is assumed to be a DatasetSource object.
Args:
features: A TensorFlow dataset or tensor of features.
source: The source from which the data was derived, e.g. a filesystem
path, an S3 URI, an HTTPS URL, a delta table name with version, or
spark table etc. If source is not a path like string,
pass in a DatasetSource object directly. If no source is specified,
a CodeDatasetSource is used, which will source information from the run
context.
targets: A TensorFlow dataset or tensor of targets. Optional.
name: The name of the dataset. If unspecified, a name is generated.
digest: A dataset digest (hash). If unspecified, a digest is computed
automatically.
get_source(dataset: mlflow.entities.dataset.Dataset | mlflow.entities.dataset_input.DatasetInput | mlflow.data.dataset.Dataset) -> mlflow.data.dataset_source.DatasetSource
Obtains the source of the specified dataset or dataset input.
Args:
dataset:
An instance of :py:class:`mlflow.data.dataset.Dataset <mlflow.data.dataset.Dataset>`,
:py:class:`mlflow.entities.Dataset`, or :py:class:`mlflow.entities.DatasetInput`.
Returns:
An instance of :py:class:`DatasetSource <mlflow.data.dataset_source.DatasetSource>`.
load_delta(path: str | None = None, table_name: str | None = None, version: str | None = None, targets: str | None = None, name: str | None = None, digest: str | None = None) -> mlflow.data.spark_dataset.SparkDataset
Loads a :py:class:`SparkDataset <mlflow.data.spark_dataset.SparkDataset>` from a Delta table
for use with MLflow Tracking.
Args:
path: The path to the Delta table. Either ``path`` or ``table_name`` must be specified.
table_name: The name of the Delta table. Either ``path`` or ``table_name`` must be
specified.
version: The Delta table version. If not specified, the version will be inferred.
targets: Optional. The name of the Delta table column containing targets (labels) for
supervised learning.
name: The name of the dataset. E.g. "wiki_train". If unspecified, a name is
automatically generated.
digest: The digest (hash, fingerprint) of the dataset. If unspecified, a digest
is automatically computed.
Returns:
An instance of :py:class:`SparkDataset <mlflow.data.spark_dataset.SparkDataset>`.
DATA
__all__ = ['get_source', 'from_pandas', 'from_numpy', 'from_huggingfac...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\data\__init__.py
mlflow.delete_assessment
Python Library Documentation: function delete_assessment in module mlflow.tracing.assessment
delete_assessment(trace_id: str, assessment_id: str)
Deletes an assessment associated with a trace.
Args:
trace_id: The ID of the trace.
assessment_id: The ID of the assessment to delete.
mlflow.delete_experiment
Python Library Documentation: function delete_experiment in module mlflow.tracking.fluent
delete_experiment(experiment_id: str) -> None
Delete an experiment from the backend store.
Args:
experiment_id: The string-ified experiment ID returned from ``create_experiment``.
.. code-block:: python
:test:
:caption: Example
import mlflow
experiment_id = mlflow.create_experiment("New Experiment")
mlflow.delete_experiment(experiment_id)
# Examine the deleted experiment details.
experiment = mlflow.get_experiment(experiment_id)
print(f"Name: {experiment.name}")
print(f"Artifact Location: {experiment.artifact_location}")
print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
print(f"Last Updated timestamp: {experiment.last_update_time}")
.. code-block:: text
:caption: Output
Name: New Experiment
Artifact Location: file:///.../mlruns/2
Lifecycle_stage: deleted
Last Updated timestamp: 1662004217511
mlflow.delete_experiment_tag
Python Library Documentation: function delete_experiment_tag in module mlflow.tracking.fluent
delete_experiment_tag(key: str) -> None
Delete a tag from the current experiment.
Args:
key: Name of the tag to be deleted.
.. code-block:: python
:test:
:caption: Example
import mlflow
exp = mlflow.set_experiment("test-delete-tag")
mlflow.set_experiment_tag("release.version", "1.0")
mlflow.delete_experiment_tag("release.version")
exp = mlflow.get_experiment(exp.experiment_id)
assert "release.version" not in exp.tags
mlflow.delete_logged_model_tag
Python Library Documentation: function delete_logged_model_tag in module mlflow.tracking.fluent
delete_logged_model_tag(model_id: str, key: str) -> None
Delete a tag from the specified logged model.
Args:
model_id: ID of the model.
key: Tag key to delete.
Example:
.. code-block:: python
:test:
import mlflow
class DummyModel(mlflow.pyfunc.PythonModel):
def predict(self, context, model_input: list[str]) -> list[str]:
return model_input
model_info = mlflow.pyfunc.log_model(name="model", python_model=DummyModel())
mlflow.set_logged_model_tags(model_info.model_id, {"key": "value"})
model = mlflow.get_logged_model(model_info.model_id)
assert model.tags["key"] == "value"
mlflow.delete_logged_model_tag(model_info.model_id, "key")
model = mlflow.get_logged_model(model_info.model_id)
assert "key" not in model.tags
mlflow.delete_prompt_alias
Python Library Documentation: function delete_prompt_alias in module mlflow.tracking._model_registry.fluent
delete_prompt_alias(name: str, alias: str) -> None
Delete an alias for a :py:class:`Prompt <mlflow.entities.Prompt>` in the MLflow Prompt Registry.
Args:
name: The name of the prompt.
alias: The alias to delete for the prompt.
mlflow.delete_run
Python Library Documentation: function delete_run in module mlflow.tracking.fluent
delete_run(run_id: str) -> None
Deletes a run with the given ID.
Args:
run_id: Unique identifier for the run to delete.
.. code-block:: python
:test:
:caption: Example
import mlflow
with mlflow.start_run() as run:
mlflow.log_param("p", 0)
run_id = run.info.run_id
mlflow.delete_run(run_id)
lifecycle_stage = mlflow.get_run(run_id).info.lifecycle_stage
print(f"run_id: {run_id}; lifecycle_stage: {lifecycle_stage}")
.. code-block:: text
:caption: Output
run_id: 45f4af3e6fd349e58579b27fcb0b8277; lifecycle_stage: deleted
mlflow.delete_tag
Python Library Documentation: function delete_tag in module mlflow.tracking.fluent
delete_tag(key: str) -> None
Delete a tag from a run. This is irreversible. If no run is active, this method
will create a new active run.
Args:
key: Name of the tag
.. code-block:: python
:test:
:caption: Example
import mlflow
tags = {"engineering": "ML Platform", "engineering_remote": "ML Platform"}
with mlflow.start_run() as run:
mlflow.set_tags(tags)
with mlflow.start_run(run_id=run.info.run_id):
mlflow.delete_tag("engineering_remote")
mlflow.delete_trace_tag
Python Library Documentation: function delete_trace_tag in module mlflow.tracing.fluent
delete_trace_tag(trace_id: 'str', key: 'str') -> 'None'
.. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
Delete a tag on the trace with the given trace ID.
The trace can be an active one or the one that has already ended and recorded in the
backend. Below is an example of deleting a tag on an active trace. You can replace the
``trace_id`` parameter to delete a tag on an already ended trace.
.. code-block:: python
:test:
import mlflow
with mlflow.start_span("my_span") as span:
mlflow.set_trace_tag(span.trace_id, "key", "value")
mlflow.delete_trace_tag(span.trace_id, "key")
Args:
trace_id: The ID of the trace to delete the tag from.
key: The string key of the tag. Must be at most 250 characters long, otherwise
it will be truncated when stored.
mlflow.delete_workspace
Python Library Documentation: function delete_workspace in module mlflow.tracking._workspace.fluent
delete_workspace(name: 'str', *, mode: 'str' = <WorkspaceDeletionMode.RESTRICT: 'RESTRICT'>) -> 'None'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Delete an existing workspace.
Args:
name: Name of the workspace to delete.
mode: Deletion mode. One of SET_DEFAULT, CASCADE, or RESTRICT.
mlflow.diffusers
Python Library Documentation: package mlflow.diffusers in mlflow
NAME
mlflow.diffusers
DESCRIPTION
The ``mlflow.diffusers`` module provides an API for logging and loading diffusion model
LoRA adapters as MLflow Models. This module exports adapter models with
the following flavors:
:py:mod:`mlflow.diffusers`
Adapter weights in safetensors format, with a reference to the base model.
:py:mod:`mlflow.pyfunc`
Produced for use by generic pyfunc-based deployment tools and batch inference.
The pyfunc wrapper loads the base diffusion pipeline and applies the adapter
at inference time.
PACKAGE CONTENTS
wrapper
CLASSES
builtins.object
DiffusersAdapterModel
class DiffusersAdapterModel(builtins.object)
| DiffusersAdapterModel(adapter_path: str, base_model: str, adapter_type: Literal['lora'], base_model_revision: str | None = None, weight_name: str | None = None) -> None
|
| A loaded LoRA adapter referencing a HuggingFace base model.
|
| Returned by :py:func:`load_model`. Call :py:meth:`load_pipeline` to get
| a ready-to-use diffusers pipeline with the adapter applied.
|
| Methods defined here:
|
| __delattr__(self, name)
| Implement delattr(self, name).
|
| __eq__(self, other)
| Return self==value.
|
| __hash__(self)
| Return hash(self).
|
| __init__(self, adapter_path: str, base_model: str, adapter_type: Literal['lora'], base_model_revision: str | None = None, weight_name: str | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| __setattr__(self, name, value)
| Implement setattr(self, name, value).
|
| load_pipeline(self, *, base_model: str | None = None, **kwargs)
| Download the base model and apply the LoRA adapter.
|
| Args:
| base_model: Override the base model reference stored at save time.
| Useful when the original local path is no longer available.
| Accepts a HuggingFace model ID or a local directory path.
| kwargs: Forwarded to ``DiffusionPipeline.from_pretrained()``.
| Common options include ``device``, ``torch_dtype``, and ``revision``.
|
| Returns:
| A ``DiffusionPipeline`` with LoRA weights applied.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'adapter_path': <class 'str'>, 'adapter_type': typi...
|
| __dataclass_fields__ = {'adapter_path': Field(name='adapter_path',type...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __match_args__ = ('adapter_path', 'base_model', 'adapter_type', 'base_...
|
| base_model_revision = None
|
| weight_name = None
FUNCTIONS
get_default_conda_env()
get_default_pip_requirements()
load_model(model_uri, dst_path=None)
.. Note:: The 'diffusers' MLflow Models integration is known to be compatible with ``0.37.0`` <= ``diffusers`` <= ``0.39.0``. MLflow Models integrations with diffusers may not succeed when used with package versions outside of this range.
Load a diffusers adapter model from a local file or a run.
Args:
model_uri: The location, in URI format, of the MLflow model. Examples:
- ``/Users/me/path/to/local/model``
- ``runs:/<mlflow_run_id>/run-relative/path/to/model``
- ``models:/<model_name>/<model_version>``
dst_path: The local filesystem path to download the model artifact to.
Returns:
A :py:class:`DiffusersAdapterModel` with adapter_path, base_model,
and adapter_type. Call ``.load_pipeline()`` to get a ready-to-use
diffusers pipeline with the adapter applied.
log_model(adapter_path, base_model, adapter_type: Literal['lora'] = 'lora', artifact_path: str | None = None, conda_env=None, code_paths=None, registered_model_name=None, signature: mlflow.models.signature.ModelSignature | None = None, input_example: Union[pandas.core.frame.DataFrame, numpy.ndarray, dict, list, ForwardRef('csr_matrix'), ForwardRef('csc_matrix'), str, bytes, tuple, NoneType] = None, await_registration_for=300, pip_requirements=None, extra_pip_requirements=None, metadata=None, params: dict[str, typing.Any] | None = None, tags: dict[str, typing.Any] | None = None, model_type: str | None = None, step: int = 0, model_id: str | None = None, name: str | None = None, **kwargs)
.. Note:: The 'diffusers' MLflow Models integration is known to be compatible with ``0.37.0`` <= ``diffusers`` <= ``0.39.0``. MLflow Models integrations with diffusers may not succeed when used with package versions outside of this range.
Log a diffusers adapter model as an MLflow artifact for the current run.
Args:
adapter_path: Path to the adapter weights. Can be a single .safetensors file
or a directory containing adapter files.
base_model: HuggingFace model ID or local path of the base diffusion model.
adapter_type: Type of adapter. Currently only "lora" is supported.
artifact_path: Deprecated. Use ``name`` instead.
conda_env: Either a dictionary representation of a Conda environment or the path to a conda
environment yaml file. If provided, this describes the environment this model should be run in.
At a minimum, it should specify the dependencies contained in `get_default_conda_env()`.
If ``None``, a conda environment with pip requirements inferred by
:func:`mlflow.models.infer_pip_requirements` is added
to the model. If the requirement inference fails, it falls back to using
`get_default_pip_requirements`. pip requirements from ``conda_env`` are written to a pip
``requirements.txt`` file and the full conda environment is written to ``conda.yaml``.
The following is an *example* dictionary representation of a conda environment::
{
"name": "mlflow-env",
"channels": ["conda-forge"],
"dependencies": [
"python=3.8.15",
{
"pip": [
"diffusers==x.y.z"
],
},
],
}
code_paths: A list of local filesystem paths to Python file dependencies (or directories
containing file dependencies). These files are *prepended* to the system path when the model
is loaded. Files declared as dependencies for a given model should have relative
imports declared from a common root path if multiple files are defined with import dependencies
between them to avoid import errors when loading the model.
For a detailed explanation of ``code_paths`` functionality, recommended usage patterns and
limitations, see the
`code_paths usage guide <https://mlflow.org/docs/latest/model/dependencies.html?highlight=code_paths#saving-extra-code-with-an-mlflow-model>`_.
registered_model_name: If given, create a model version under this name.
signature: an instance of the :py:class:`ModelSignature <mlflow.models.ModelSignature>`
class that describes the model's inputs and outputs. If not specified but an
``input_example`` is supplied, a signature will be automatically inferred
based on the supplied input example and model. To disable automatic signature
inference when providing an input example, set ``signature`` to ``False``.
To manually infer a model signature, call
:py:func:`infer_signature() <mlflow.models.infer_signature>` on datasets
with valid model inputs, such as a training dataset with the target column
omitted, and valid model outputs, like model predictions made on the training
dataset, for example:
.. code-block:: python
from mlflow.models import infer_signature
train = df.drop_column("target_label")
predictions = ... # compute model predictions
signature = infer_signature(train, predictions)
input_example: one or several instances of valid model input. The input example is used
as a hint of what data to feed the model. It will be converted to a Pandas
DataFrame and then serialized to json using the Pandas split-oriented
format, or a numpy array where the example will be serialized to json
by converting it to a list. Bytes are base64-encoded. When the ``signature`` parameter is
``None``, the input example is used to infer a model signature.
await_registration_for: Number of seconds to wait for model version creation.
pip_requirements: Either an iterable of pip requirement strings
(e.g. ``["diffusers", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes the environment this model should be run in. If ``None``, a default list of requirements
is inferred by :func:`mlflow.models.infer_pip_requirements` from the current software environment.
If the requirement inference fails, it falls back to using `get_default_pip_requirements`.
Both requirements and constraints are automatically parsed and written to ``requirements.txt`` and
``constraints.txt`` files, respectively, and stored as part of the model. Requirements are also
written to the ``pip`` section of the model's conda environment (``conda.yaml``) file.
extra_pip_requirements: Either an iterable of pip
requirement strings
(e.g. ``["pandas", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes additional pip requirements that are appended to a default set of pip requirements
generated automatically based on the user's current software environment. Both requirements and
constraints are automatically parsed and written to ``requirements.txt`` and ``constraints.txt``
files, respectively, and stored as part of the model. Requirements are also written to the ``pip``
section of the model's conda environment (``conda.yaml``) file.
.. warning::
The following arguments can't be specified at the same time:
- ``conda_env``
- ``pip_requirements``
- ``extra_pip_requirements``
`This example <https://github.com/mlflow/mlflow/blob/master/examples/pip_requirements/pip_requirements.py>`_ demonstrates how to specify pip requirements using
``pip_requirements`` and ``extra_pip_requirements``.
metadata: Custom metadata dictionary passed to the model and stored in the MLmodel file.
params: A dictionary of parameters to log with the model.
tags: A dictionary of tags to log with the model.
model_type: The type of the model.
step: The step at which to log the model outputs and metrics
model_id: The ID of the model.
name: Model name.
kwargs: Extra arguments to pass to :py:func:`mlflow.models.Model.log`.
Returns:
A :py:class:`ModelInfo <mlflow.models.model.ModelInfo>` instance.
save_model(adapter_path: str, path: str, base_model: str, adapter_type: Literal['lora'] = 'lora', conda_env=None, code_paths: list[str] | None = None, mlflow_model: mlflow.models.model.Model | None = None, signature: mlflow.models.signature.ModelSignature | None = None, input_example: Union[pandas.core.frame.DataFrame, numpy.ndarray, dict, list, ForwardRef('csr_matrix'), ForwardRef('csc_matrix'), str, bytes, tuple, NoneType] = None, pip_requirements: list[str] | str | None = None, extra_pip_requirements: list[str] | str | None = None, metadata: dict[str, typing.Any] | None = None) -> None
.. Note:: The 'diffusers' MLflow Models integration is known to be compatible with ``0.37.0`` <= ``diffusers`` <= ``0.39.0``. MLflow Models integrations with diffusers may not succeed when used with package versions outside of this range.
Save a diffusers adapter model to a path on the local file system.
Args:
adapter_path: Path to the adapter weights. Can be a single .safetensors file
or a directory containing adapter files. Single files and directories
containing a single safetensors file are normalized to
``pytorch_lora_weights.safetensors`` to match the convention expected
by ``load_lora_weights()``. Directories with multiple weight files
are copied as-is.
path: Local path where the model is to be saved.
base_model: HuggingFace model ID or local path of the base diffusion model
that this adapter was trained on (e.g., "black-forest-labs/FLUX.1-dev").
adapter_type: Type of adapter. Currently only "lora" is supported.
conda_env: Either a dictionary representation of a Conda environment or the path to a conda
environment yaml file. If provided, this describes the environment this model should be run in.
At a minimum, it should specify the dependencies contained in `get_default_conda_env()`.
If ``None``, a conda environment with pip requirements inferred by
:func:`mlflow.models.infer_pip_requirements` is added
to the model. If the requirement inference fails, it falls back to using
`get_default_pip_requirements`. pip requirements from ``conda_env`` are written to a pip
``requirements.txt`` file and the full conda environment is written to ``conda.yaml``.
The following is an *example* dictionary representation of a conda environment::
{
"name": "mlflow-env",
"channels": ["conda-forge"],
"dependencies": [
"python=3.8.15",
{
"pip": [
"diffusers==x.y.z"
],
},
],
}
code_paths: A list of local filesystem paths to Python file dependencies (or directories
containing file dependencies). These files are *prepended* to the system path when the model
is loaded. Files declared as dependencies for a given model should have relative
imports declared from a common root path if multiple files are defined with import dependencies
between them to avoid import errors when loading the model.
For a detailed explanation of ``code_paths`` functionality, recommended usage patterns and
limitations, see the
`code_paths usage guide <https://mlflow.org/docs/latest/model/dependencies.html?highlight=code_paths#saving-extra-code-with-an-mlflow-model>`_.
mlflow_model: :py:mod:`mlflow.models.Model` this flavor is being added to.
signature: an instance of the :py:class:`ModelSignature <mlflow.models.ModelSignature>`
class that describes the model's inputs and outputs. If not specified but an
``input_example`` is supplied, a signature will be automatically inferred
based on the supplied input example and model. To disable automatic signature
inference when providing an input example, set ``signature`` to ``False``.
To manually infer a model signature, call
:py:func:`infer_signature() <mlflow.models.infer_signature>` on datasets
with valid model inputs, such as a training dataset with the target column
omitted, and valid model outputs, like model predictions made on the training
dataset, for example:
.. code-block:: python
from mlflow.models import infer_signature
train = df.drop_column("target_label")
predictions = ... # compute model predictions
signature = infer_signature(train, predictions)
input_example: one or several instances of valid model input. The input example is used
as a hint of what data to feed the model. It will be converted to a Pandas
DataFrame and then serialized to json using the Pandas split-oriented
format, or a numpy array where the example will be serialized to json
by converting it to a list. Bytes are base64-encoded. When the ``signature`` parameter is
``None``, the input example is used to infer a model signature.
pip_requirements: Either an iterable of pip requirement strings
(e.g. ``["diffusers", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes the environment this model should be run in. If ``None``, a default list of requirements
is inferred by :func:`mlflow.models.infer_pip_requirements` from the current software environment.
If the requirement inference fails, it falls back to using `get_default_pip_requirements`.
Both requirements and constraints are automatically parsed and written to ``requirements.txt`` and
``constraints.txt`` files, respectively, and stored as part of the model. Requirements are also
written to the ``pip`` section of the model's conda environment (``conda.yaml``) file.
extra_pip_requirements: Either an iterable of pip
requirement strings
(e.g. ``["pandas", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes additional pip requirements that are appended to a default set of pip requirements
generated automatically based on the user's current software environment. Both requirements and
constraints are automatically parsed and written to ``requirements.txt`` and ``constraints.txt``
files, respectively, and stored as part of the model. Requirements are also written to the ``pip``
section of the model's conda environment (``conda.yaml``) file.
.. warning::
The following arguments can't be specified at the same time:
- ``conda_env``
- ``pip_requirements``
- ``extra_pip_requirements``
`This example <https://github.com/mlflow/mlflow/blob/master/examples/pip_requirements/pip_requirements.py>`_ demonstrates how to specify pip requirements using
``pip_requirements`` and ``extra_pip_requirements``.
metadata: Custom metadata dictionary passed to the model and stored in the MLmodel file.
DATA
__all__ = ['DiffusersAdapterModel', 'load_model', 'save_model', 'log_m...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\diffusers\__init__.py
mlflow.disable_system_metrics_logging
Python Library Documentation: function disable_system_metrics_logging in module mlflow.system_metrics
disable_system_metrics_logging()
Disable system metrics logging globally.
Calling this function will disable system metrics logging globally, but users can still opt in
system metrics logging for individual runs by `mlflow.start_run(log_system_metrics=True)`.
mlflow.doctor
Python Library Documentation: function doctor in module mlflow.utils.doctor
doctor(mask_envs=False)
Prints out useful information for debugging issues with MLflow.
Args:
mask_envs: If True, mask the MLflow environment variable values
(e.g. `"MLFLOW_ENV_VAR": "***"`) in the output to prevent leaking sensitive
information.
.. warning::
- This API should only be used for debugging purposes.
- The output may contain sensitive information such as a database URI containing a password.
.. code-block:: python
:caption: Example
import mlflow
with mlflow.start_run():
mlflow.doctor()
.. code-block:: text
:caption: Output
System information: Linux #58~20.04.1-Ubuntu SMP Thu Oct 13 13:09:46 UTC 2022
Python version: 3.8.13
MLflow version: 2.0.1
MLflow module location: /usr/local/lib/python3.8/site-packages/mlflow/__init__.py
Tracking URI: sqlite:///mlflow.db
Registry URI: sqlite:///mlflow.db
MLflow environment variables:
MLFLOW_TRACKING_URI: sqlite:///mlflow.db
MLflow dependencies:
Flask: 2.2.2
Jinja2: 3.0.3
alembic: 1.8.1
click: 8.1.3
cloudpickle: 2.2.0
databricks-cli: 0.17.4.dev0
docker: 6.0.0
entrypoints: 0.4
gitpython: 3.1.29
gunicorn: 20.1.0
importlib-metadata: 5.0.0
markdown: 3.4.1
matplotlib: 3.6.1
numpy: 1.23.4
packaging: 21.3
pandas: 1.5.1
protobuf: 3.19.6
pyarrow: 9.0.0
pytz: 2022.6
pyyaml: 6.0
querystring-parser: 1.2.4
requests: 2.28.1
scikit-learn: 1.1.3
scipy: 1.9.3
shap: 0.41.0
sqlalchemy: 1.4.42
sqlparse: 0.4.3
mlflow.dspy
Python Library Documentation: package mlflow.dspy in mlflow
NAME
mlflow.dspy
PACKAGE CONTENTS
autolog
callback
constant
load
save
util
wrapper
FUNCTIONS
_load_pyfunc(path)
autolog(log_traces: bool = True, log_traces_from_compile: bool = False, log_traces_from_eval: bool = True, log_compiles: bool = False, log_evals: bool = False, disable: bool = False, silent: bool = False)
Enables (or disables) and configures autologging from DSPy to MLflow. Currently, the
MLflow DSPy flavor only supports autologging for tracing.
Args:
log_traces: If ``True``, traces are logged for DSPy models by using. If ``False``,
no traces are collected during inference. Default to ``True``.
log_traces_from_compile: If ``True``, traces are logged when compiling (optimizing)
DSPy programs. If ``False``, traces are only logged from normal model inference and
disabled when compiling. Default to ``False``.
log_traces_from_eval: If ``True``, traces are logged for DSPy models when running DSPy's
`built-in evaluator <https://dspy.ai/learn/evaluation/metrics/#evaluation>`_.
If ``False``, traces are only logged from normal model inference and disabled when
running the evaluator. Default to ``True``.
log_compiles: If ``True``, information about the optimization process is logged when
`Teleprompter.compile()` is called.
log_evals: If ``True``, information about the evaluation call is logged when
`Evaluate.__call__()` is called.
disable: If ``True``, disables the DSPy autologging integration. If ``False``,
enables the DSPy autologging integration.
silent: If ``True``, suppress all event logs and warnings from MLflow during DSPy
autologging. If ``False``, show all events and warnings.
load_model(model_uri, dst_path=None)
Load a Dspy model from a run.
This function will also set the global dspy settings `dspy.settings` by the saved settings.
Args:
model_uri: The location, in URI format, of the MLflow model. For example:
- ``/Users/me/path/to/local/model``
- ``relative/path/to/local/model``
- ``s3://my_bucket/path/to/model``
- ``runs:/<mlflow_run_id>/run-relative/path/to/model``
- ``mlflow-artifacts:/path/to/model``
For more information about supported URI schemes, see
`Referencing Artifacts <https://www.mlflow.org/docs/latest/tracking.html#
artifact-locations>`_.
dst_path: The local filesystem path to utilize for downloading the model artifact.
This directory must already exist if provided. If unspecified, a local output
path will be created.
Returns:
An `dspy.module` instance, representing the dspy model.
log_model(dspy_model, artifact_path: str | None = None, task: str | None = None, model_config: dict[str, typing.Any] | None = None, code_paths: list[str] | None = None, conda_env: list[str] | str | None = None, signature: mlflow.models.signature.ModelSignature | None = None, input_example: Union[pandas.core.frame.DataFrame, numpy.ndarray, dict, list, ForwardRef('csr_matrix'), ForwardRef('csc_matrix'), str, bytes, tuple, NoneType] = None, registered_model_name: str | None = None, await_registration_for: int = 300, pip_requirements: list[str] | str | None = None, extra_pip_requirements: list[str] | str | None = None, metadata: dict[str, typing.Any] | None = None, resources: str | pathlib.Path | list[mlflow.models.resources.Resource] | None = None, prompts: list[str | mlflow.entities.model_registry.prompt.Prompt] | None = None, name: str | None = None, params: dict[str, typing.Any] | None = None, tags: dict[str, typing.Any] | None = None, model_type: str | None = None, step: int = 0, model_id: str | None = None, use_dspy_model_save: bool = False)
Log a Dspy model along with metadata to MLflow.
This method saves a Dspy model along with metadata such as model signature and conda
environments to MLflow.
Args:
dspy_model: an instance of `dspy.Module`. The Dspy model to be saved.
artifact_path: Deprecated. Use `name` instead.
task: defaults to None. The task type of the model. Can only be `llm/v1/chat` or None for
now.
model_config: keyword arguments to be passed to the Dspy Module at instantiation.
code_paths: A list of local filesystem paths to Python file dependencies (or directories
containing file dependencies). These files are *prepended* to the system path when the model
is loaded. Files declared as dependencies for a given model should have relative
imports declared from a common root path if multiple files are defined with import dependencies
between them to avoid import errors when loading the model.
For a detailed explanation of ``code_paths`` functionality, recommended usage patterns and
limitations, see the
`code_paths usage guide <https://mlflow.org/docs/latest/model/dependencies.html?highlight=code_paths#saving-extra-code-with-an-mlflow-model>`_.
conda_env: Either a dictionary representation of a Conda environment or the path to a conda
environment yaml file. If provided, this describes the environment this model should be run in.
At a minimum, it should specify the dependencies contained in `get_default_conda_env()`.
If ``None``, a conda environment with pip requirements inferred by
:func:`mlflow.models.infer_pip_requirements` is added
to the model. If the requirement inference fails, it falls back to using
`get_default_pip_requirements`. pip requirements from ``conda_env`` are written to a pip
``requirements.txt`` file and the full conda environment is written to ``conda.yaml``.
The following is an *example* dictionary representation of a conda environment::
{
"name": "mlflow-env",
"channels": ["conda-forge"],
"dependencies": [
"python=3.8.15",
{
"pip": [
"dspy==x.y.z"
],
},
],
}
signature: an instance of the :py:class:`ModelSignature <mlflow.models.ModelSignature>`
class that describes the model's inputs and outputs. If not specified but an
``input_example`` is supplied, a signature will be automatically inferred
based on the supplied input example and model. To disable automatic signature
inference when providing an input example, set ``signature`` to ``False``.
To manually infer a model signature, call
:py:func:`infer_signature() <mlflow.models.infer_signature>` on datasets
with valid model inputs, such as a training dataset with the target column
omitted, and valid model outputs, like model predictions made on the training
dataset, for example:
.. code-block:: python
from mlflow.models import infer_signature
train = df.drop_column("target_label")
predictions = ... # compute model predictions
signature = infer_signature(train, predictions)
input_example: one or several instances of valid model input. The input example is used
as a hint of what data to feed the model. It will be converted to a Pandas
DataFrame and then serialized to json using the Pandas split-oriented
format, or a numpy array where the example will be serialized to json
by converting it to a list. Bytes are base64-encoded. When the ``signature`` parameter is
``None``, the input example is used to infer a model signature.
registered_model_name: defaults to None. If set, create a model version under
`registered_model_name`, also create a registered model if one with the given name does
not exist.
await_registration_for: defaults to
`mlflow.tracking._model_registry.DEFAULT_AWAIT_MAX_SLEEP_SECONDS`. Number of
seconds to wait for the model version to finish being created and is in ``READY``
status. By default, the function waits for five minutes. Specify 0 or None to skip
waiting.
pip_requirements: Either an iterable of pip requirement strings
(e.g. ``["dspy", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes the environment this model should be run in. If ``None``, a default list of requirements
is inferred by :func:`mlflow.models.infer_pip_requirements` from the current software environment.
If the requirement inference fails, it falls back to using `get_default_pip_requirements`.
Both requirements and constraints are automatically parsed and written to ``requirements.txt`` and
``constraints.txt`` files, respectively, and stored as part of the model. Requirements are also
written to the ``pip`` section of the model's conda environment (``conda.yaml``) file.
extra_pip_requirements: Either an iterable of pip
requirement strings
(e.g. ``["pandas", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes additional pip requirements that are appended to a default set of pip requirements
generated automatically based on the user's current software environment. Both requirements and
constraints are automatically parsed and written to ``requirements.txt`` and ``constraints.txt``
files, respectively, and stored as part of the model. Requirements are also written to the ``pip``
section of the model's conda environment (``conda.yaml``) file.
.. warning::
The following arguments can't be specified at the same time:
- ``conda_env``
- ``pip_requirements``
- ``extra_pip_requirements``
`This example <https://github.com/mlflow/mlflow/blob/master/examples/pip_requirements/pip_requirements.py>`_ demonstrates how to specify pip requirements using
``pip_requirements`` and ``extra_pip_requirements``.
metadata: Custom metadata dictionary passed to the model and stored in the MLmodel
file.
resources: A list of model resources or a resources.yaml file containing a list of
resources required to serve the model.
prompts: A list of prompt URIs registered in the MLflow Prompt Registry, to be associated with the model.
Each prompt URI should be in the form ``prompt:/<name>/<version>``. The prompts should be
registered in the MLflow Prompt Registry before being associated with the model.
This will create a mutual link between the model and the prompt. The associated prompts can be
seen in the model's metadata stored in the MLmodel file. From the Prompt Registry UI, you can
navigate to the model as well.
.. code-block:: python
import mlflow
prompt_template = "Hi, {name}! How are you doing today?"
# Register a prompt in the MLflow Prompt Registry
mlflow.prompts.register_prompt("my_prompt", prompt_template, description="A simple prompt")
# Log a model with the registered prompt
with mlflow.start_run():
model_info = mlflow.pyfunc.log_model(
name=MyModel(),
name="model",
prompts=["prompt:/my_prompt/1"]
)
print(model_info.prompts)
# Output: ['prompt:/my_prompt/1']
# Load the prompt
prompt = mlflow.genai.load_prompt(model_info.prompts[0])
name: Model name.
params: A dictionary of parameters to log with the model.
tags: A dictionary of tags to log with the model.
model_type: The type of the model.
step: The step at which to log the model outputs and metrics
model_id: The ID of the model.
use_dspy_model_save: Whether to save the Dspy model by dspy builtin `dspy.Module.save`
method.
.. code-block:: python
:caption: Example
import dspy
import mlflow
from mlflow.models import ModelSignature
from mlflow.types.schema import ColSpec, Schema
# Set up the LM.
lm = dspy.LM(model="openai/gpt-4o-mini", max_tokens=250)
dspy.settings.configure(lm=lm)
class CoT(dspy.Module):
def __init__(self):
super().__init__()
self.prog = dspy.ChainOfThought("question -> answer")
def forward(self, question):
return self.prog(question=question)
dspy_model = CoT()
mlflow.set_tracking_uri("http://127.0.0.1:5000")
mlflow.set_experiment("test-dspy-logging")
from mlflow.dspy import log_model
input_schema = Schema([ColSpec("string")])
output_schema = Schema([ColSpec("string")])
signature = ModelSignature(inputs=input_schema, outputs=output_schema)
with mlflow.start_run():
log_model(
dspy_model,
"model",
input_example="what is 2 + 2?",
signature=signature,
)
save_model(model, path: str, task: str | None = None, model_config: dict[str, typing.Any] | None = None, code_paths: list[str] | None = None, mlflow_model: mlflow.models.model.Model | None = None, conda_env: list[str] | str | None = None, signature: mlflow.models.signature.ModelSignature | None = None, input_example: Union[pandas.core.frame.DataFrame, numpy.ndarray, dict, list, ForwardRef('csr_matrix'), ForwardRef('csc_matrix'), str, bytes, tuple, NoneType] = None, pip_requirements: list[str] | str | None = None, extra_pip_requirements: list[str] | str | None = None, metadata: dict[str, typing.Any] | None = None, resources: str | pathlib.Path | list[mlflow.models.resources.Resource] | None = None, use_dspy_model_save: bool = False)
Save a Dspy model.
This method saves a Dspy model along with metadata such as model signature and conda
environments to local file system. This method is called inside `mlflow.dspy.log_model()`.
Args:
model: an instance of `dspy.Module`. The Dspy model/module to be saved.
path: local path where the MLflow model is to be saved.
task: defaults to None. The task type of the model. Can only be `llm/v1/chat` or None for
now.
model_config: keyword arguments to be passed to the Dspy Module at instantiation.
code_paths: A list of local filesystem paths to Python file dependencies (or directories
containing file dependencies). These files are *prepended* to the system path when the model
is loaded. Files declared as dependencies for a given model should have relative
imports declared from a common root path if multiple files are defined with import dependencies
between them to avoid import errors when loading the model.
For a detailed explanation of ``code_paths`` functionality, recommended usage patterns and
limitations, see the
`code_paths usage guide <https://mlflow.org/docs/latest/model/dependencies.html?highlight=code_paths#saving-extra-code-with-an-mlflow-model>`_.
mlflow_model: an instance of `mlflow.models.Model`, defaults to None. MLflow model
configuration to which to add the Dspy model metadata. If None, a blank instance will
be created.
conda_env: Either a dictionary representation of a Conda environment or the path to a conda
environment yaml file. If provided, this describes the environment this model should be run in.
At a minimum, it should specify the dependencies contained in `get_default_conda_env()`.
If ``None``, a conda environment with pip requirements inferred by
:func:`mlflow.models.infer_pip_requirements` is added
to the model. If the requirement inference fails, it falls back to using
`get_default_pip_requirements`. pip requirements from ``conda_env`` are written to a pip
``requirements.txt`` file and the full conda environment is written to ``conda.yaml``.
The following is an *example* dictionary representation of a conda environment::
{
"name": "mlflow-env",
"channels": ["conda-forge"],
"dependencies": [
"python=3.8.15",
{
"pip": [
"dspy==x.y.z"
],
},
],
}
signature: an instance of the :py:class:`ModelSignature <mlflow.models.ModelSignature>`
class that describes the model's inputs and outputs. If not specified but an
``input_example`` is supplied, a signature will be automatically inferred
based on the supplied input example and model. To disable automatic signature
inference when providing an input example, set ``signature`` to ``False``.
To manually infer a model signature, call
:py:func:`infer_signature() <mlflow.models.infer_signature>` on datasets
with valid model inputs, such as a training dataset with the target column
omitted, and valid model outputs, like model predictions made on the training
dataset, for example:
.. code-block:: python
from mlflow.models import infer_signature
train = df.drop_column("target_label")
predictions = ... # compute model predictions
signature = infer_signature(train, predictions)
input_example: one or several instances of valid model input. The input example is used
as a hint of what data to feed the model. It will be converted to a Pandas
DataFrame and then serialized to json using the Pandas split-oriented
format, or a numpy array where the example will be serialized to json
by converting it to a list. Bytes are base64-encoded. When the ``signature`` parameter is
``None``, the input example is used to infer a model signature.
pip_requirements: Either an iterable of pip requirement strings
(e.g. ``["dspy", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes the environment this model should be run in. If ``None``, a default list of requirements
is inferred by :func:`mlflow.models.infer_pip_requirements` from the current software environment.
If the requirement inference fails, it falls back to using `get_default_pip_requirements`.
Both requirements and constraints are automatically parsed and written to ``requirements.txt`` and
``constraints.txt`` files, respectively, and stored as part of the model. Requirements are also
written to the ``pip`` section of the model's conda environment (``conda.yaml``) file.
extra_pip_requirements: Either an iterable of pip
requirement strings
(e.g. ``["pandas", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes additional pip requirements that are appended to a default set of pip requirements
generated automatically based on the user's current software environment. Both requirements and
constraints are automatically parsed and written to ``requirements.txt`` and ``constraints.txt``
files, respectively, and stored as part of the model. Requirements are also written to the ``pip``
section of the model's conda environment (``conda.yaml``) file.
.. warning::
The following arguments can't be specified at the same time:
- ``conda_env``
- ``pip_requirements``
- ``extra_pip_requirements``
`This example <https://github.com/mlflow/mlflow/blob/master/examples/pip_requirements/pip_requirements.py>`_ demonstrates how to specify pip requirements using
``pip_requirements`` and ``extra_pip_requirements``.
metadata: Custom metadata dictionary passed to the model and stored in the MLmodel file.
resources: A list of model resources or a resources.yaml file containing a list of
resources required to serve the model.
use_dspy_model_save: Whether to save the Dspy model by dspy builtin `dspy.Module.save`
method.
DATA
__all__ = ['autolog', 'save_model', 'log_model', 'load_model', '_load_...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\dspy\__init__.py
mlflow.enable_system_metrics_logging
Python Library Documentation: function enable_system_metrics_logging in module mlflow.system_metrics
enable_system_metrics_logging()
Enable system metrics logging globally.
Calling this function will enable system metrics logging globally, but users can still opt out
system metrics logging for individual runs by `mlflow.start_run(log_system_metrics=False)`.
mlflow.end_run
Python Library Documentation: function end_run in module mlflow.tracking.fluent
end_run(status: str = 'FINISHED') -> None
End an active MLflow run (if there is one).
.. code-block:: python
:test:
:caption: Example
import mlflow
# Start run and get status
mlflow.start_run()
run = mlflow.active_run()
print(f"run_id: {run.info.run_id}; status: {run.info.status}")
# End run and get status
mlflow.end_run()
run = mlflow.get_run(run.info.run_id)
print(f"run_id: {run.info.run_id}; status: {run.info.status}")
print("--")
# Check for any active runs
print(f"Active run: {mlflow.active_run()}")
.. code-block:: text
:caption: Output
run_id: b47ee4563368419880b44ad8535f6371; status: RUNNING
run_id: b47ee4563368419880b44ad8535f6371; status: FINISHED
--
Active run: None
mlflow.entities
Python Library Documentation: package mlflow.entities in mlflow
NAME
mlflow.entities
DESCRIPTION
The ``mlflow.entities`` module defines entities returned by the MLflow
`REST API <../rest-api.html>`_.
PACKAGE CONTENTS
_job
_job_status
_mlflow_object
assessment
assessment_error
assessment_source
dataset
dataset_input
dataset_record
dataset_record_source
dataset_summary
document
entity_type
evaluation_dataset
experiment
experiment_tag
file_info
gateway_budget_policy
gateway_endpoint
gateway_guardrail
gateway_secrets
input_tag
issue
lifecycle_stage
link
logged_model
logged_model_input
logged_model_output
logged_model_parameter
logged_model_status
logged_model_tag
mcp_access_endpoint
mcp_server
mcp_server_version
metric
model_registry (package)
multipart_upload
param
presigned_download
presigned_upload
run
run_data
run_info
run_inputs
run_outputs
run_status
run_tag
scorer
session
source_type
span
span_event
span_log_level
span_status
trace
trace_data
trace_info
trace_info_v2
trace_location
trace_metrics
trace_state
trace_status
view_type
webhook
workspace
CLASSES
builtins.object
mlflow.entities.assessment_source.AssessmentSourceType
mlflow.entities.dataset_summary._DatasetSummary
mlflow.entities.document.Document
mlflow.entities.entity_type.EntityAssociationType
mlflow.entities.gateway_budget_policy.BudgetDuration
mlflow.entities.lifecycle_stage.LifecycleStage
mlflow.entities.mcp_access_endpoint.MCPAccessEndpoint
mlflow.entities.mcp_server.MCPServer
mlflow.entities.mcp_server.MCPTool
mlflow.entities.mcp_server_version.ConnectOptionSettings
mlflow.entities.mcp_server_version.MCPServerVersion
mlflow.entities.model_registry.prompt.Prompt
mlflow.entities.run_status.RunStatus
mlflow.entities.session.Session
mlflow.entities.source_type.SourceType
mlflow.entities.span.Span
mlflow.entities.span.LiveSpan
mlflow.entities.span.NoOpSpan
mlflow.entities.span.SpanType
mlflow.entities.span_status.SpanStatus
mlflow.entities.trace_data.TraceData
mlflow.entities.view_type.ViewType
mlflow.entities.webhook.Webhook
mlflow.entities.webhook.WebhookEvent
mlflow.entities.webhook.WebhookTestResult
mlflow.entities.workspace.TraceArchivalConfig
mlflow.entities.workspace.Workspace
builtins.str(builtins.object)
mlflow.entities.dataset_record_source.DatasetRecordSourceType(builtins.str, enum.Enum)
mlflow.entities.gateway_budget_policy.BudgetAction(builtins.str, enum.Enum)
mlflow.entities.gateway_budget_policy.BudgetDurationUnit(builtins.str, enum.Enum)
mlflow.entities.gateway_budget_policy.BudgetTargetScope(builtins.str, enum.Enum)
mlflow.entities.gateway_budget_policy.BudgetUnit(builtins.str, enum.Enum)
mlflow.entities.gateway_endpoint.FallbackStrategy(builtins.str, enum.Enum)
mlflow.entities.gateway_endpoint.GatewayModelLinkageType(builtins.str, enum.Enum)
mlflow.entities.gateway_endpoint.GatewayResourceType(builtins.str, enum.Enum)
mlflow.entities.gateway_endpoint.RoutingStrategy(builtins.str, enum.Enum)
mlflow.entities.gateway_guardrail.GuardrailAction(builtins.str, enum.Enum)
mlflow.entities.gateway_guardrail.GuardrailStage(builtins.str, enum.Enum)
mlflow.entities.issue.IssueSeverity(builtins.str, enum.Enum)
mlflow.entities.issue.IssueStatus(builtins.str, enum.Enum)
mlflow.entities.logged_model_status.LoggedModelStatus(builtins.str, enum.Enum)
mlflow.entities.mcp_server.MCPRemoteTransportType(builtins.str, enum.Enum)
mlflow.entities.mcp_server.MCPStatus(builtins.str, enum.Enum)
mlflow.entities.span_status.SpanStatusCode(builtins.str, enum.Enum)
mlflow.entities.trace_location.TraceLocationType(builtins.str, enum.Enum)
mlflow.entities.trace_state.TraceState(builtins.str, enum.Enum)
mlflow.entities.webhook.WebhookStatus(builtins.str, enum.Enum)
mlflow.entities.workspace.WorkspaceDeletionMode(builtins.str, enum.Enum)
enum.Enum(builtins.object)
mlflow.entities.dataset_record_source.DatasetRecordSourceType(builtins.str, enum.Enum)
mlflow.entities.gateway_budget_policy.BudgetAction(builtins.str, enum.Enum)
mlflow.entities.gateway_budget_policy.BudgetDurationUnit(builtins.str, enum.Enum)
mlflow.entities.gateway_budget_policy.BudgetTargetScope(builtins.str, enum.Enum)
mlflow.entities.gateway_budget_policy.BudgetUnit(builtins.str, enum.Enum)
mlflow.entities.gateway_endpoint.FallbackStrategy(builtins.str, enum.Enum)
mlflow.entities.gateway_endpoint.GatewayModelLinkageType(builtins.str, enum.Enum)
mlflow.entities.gateway_endpoint.GatewayResourceType(builtins.str, enum.Enum)
mlflow.entities.gateway_endpoint.RoutingStrategy(builtins.str, enum.Enum)
mlflow.entities.gateway_guardrail.GuardrailAction(builtins.str, enum.Enum)
mlflow.entities.gateway_guardrail.GuardrailStage(builtins.str, enum.Enum)
mlflow.entities.issue.IssueSeverity(builtins.str, enum.Enum)
mlflow.entities.issue.IssueStatus(builtins.str, enum.Enum)
mlflow.entities.logged_model_status.LoggedModelStatus(builtins.str, enum.Enum)
mlflow.entities.mcp_server.MCPRemoteTransportType(builtins.str, enum.Enum)
mlflow.entities.mcp_server.MCPStatus(builtins.str, enum.Enum)
mlflow.entities.span_status.SpanStatusCode(builtins.str, enum.Enum)
mlflow.entities.trace_location.TraceLocationType(builtins.str, enum.Enum)
mlflow.entities.trace_state.TraceState(builtins.str, enum.Enum)
mlflow.entities.webhook.WebhookStatus(builtins.str, enum.Enum)
mlflow.entities.workspace.WorkspaceDeletionMode(builtins.str, enum.Enum)
enum.IntEnum(builtins.int, enum.ReprEnum)
mlflow.entities.span_log_level.SpanLogLevel
mlflow.entities._mlflow_object._MlflowObject(builtins.object)
mlflow.entities.assessment.Assessment
mlflow.entities.assessment.Expectation
mlflow.entities.assessment.Feedback
mlflow.entities.assessment.IssueReference
mlflow.entities.assessment_error.AssessmentError
mlflow.entities.assessment_source.AssessmentSource
mlflow.entities.dataset.Dataset
mlflow.entities.dataset_input.DatasetInput
mlflow.entities.dataset_record.DatasetRecord
mlflow.entities.dataset_record_source.DatasetRecordSource
mlflow.entities.experiment.Experiment
mlflow.entities.experiment_tag.ExperimentTag
mlflow.entities.file_info.FileInfo
mlflow.entities.gateway_budget_policy.GatewayBudgetPolicy
mlflow.entities.gateway_endpoint.FallbackConfig
mlflow.entities.gateway_endpoint.GatewayEndpoint
mlflow.entities.gateway_endpoint.GatewayEndpointBinding
mlflow.entities.gateway_endpoint.GatewayEndpointModelConfig
mlflow.entities.gateway_endpoint.GatewayEndpointModelMapping
mlflow.entities.gateway_endpoint.GatewayEndpointTag
mlflow.entities.gateway_endpoint.GatewayModelDefinition
mlflow.entities.gateway_guardrail.GatewayGuardrail
mlflow.entities.gateway_guardrail.GatewayGuardrailConfig
mlflow.entities.gateway_secrets.GatewaySecretInfo
mlflow.entities.input_tag.InputTag
mlflow.entities.issue.Issue
mlflow.entities.link.Link
mlflow.entities.logged_model.LoggedModel
mlflow.entities.logged_model_input.LoggedModelInput
mlflow.entities.logged_model_output.LoggedModelOutput
mlflow.entities.logged_model_parameter.LoggedModelParameter
mlflow.entities.logged_model_tag.LoggedModelTag
mlflow.entities.metric.Metric
mlflow.entities.param.Param
mlflow.entities.run.Run
mlflow.entities.run_data.RunData
mlflow.entities.run_info.RunInfo
mlflow.entities.run_inputs.RunInputs
mlflow.entities.run_outputs.RunOutputs
mlflow.entities.run_tag.RunTag
mlflow.entities.scorer.ScorerVersion
mlflow.entities.span_event.SpanEvent
mlflow.entities.trace.Trace
mlflow.entities.trace_info.TraceInfo
mlflow.entities.trace_location.TraceLocation
mlflow.entities.trace_location.TraceLocationBase(mlflow.entities._mlflow_object._MlflowObject, abc.ABC)
mlflow.entities.trace_location.InferenceTableLocation
mlflow.entities.trace_location.MlflowExperimentLocation
mlflow.entities.trace_location.UCSchemaLocation
mlflow.entities.trace_location.UnityCatalog
class Assessment(mlflow.entities._mlflow_object._MlflowObject)
| Assessment(name: 'str', source: 'AssessmentSource', trace_id: 'str | None' = None, run_id: 'str | None' = None, rationale: 'str | None' = None, metadata: 'dict[str, str] | None' = None, span_id: 'str | None' = None, create_time_ms: 'int | None' = None, last_update_time_ms: 'int | None' = None, assessment_id: 'str | None' = None, error: 'AssessmentError | None' = None, expectation: 'ExpectationValue | None' = None, feedback: 'FeedbackValue | None' = None, issue: 'IssueReferenceValue | None' = None, overrides: 'str | None' = None, valid: 'bool | None' = None) -> None
|
| Base class for assessments that can be attached to a trace.
| An Assessment should be one of the following types:
|
| - Expectations: A label that represents the expected value for a particular operation.
| For example, an expected answer for a user question from a chatbot.
| - Feedback: A label that represents the feedback on the quality of the operation.
| Feedback can come from different sources, such as human judges, heuristic scorers,
| or LLM-as-a-Judge.
| - IssueReference: A reference to an issue associated with a trace, used to link traces
| to discovered quality or operational problems.
|
| Method resolution order:
| Assessment
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, name: 'str', source: 'AssessmentSource', trace_id: 'str | None' = None, run_id: 'str | None' = None, rationale: 'str | None' = None, metadata: 'dict[str, str] | None' = None, span_id: 'str | None' = None, create_time_ms: 'int | None' = None, last_update_time_ms: 'int | None' = None, assessment_id: 'str | None' = None, error: 'AssessmentError | None' = None, expectation: 'ExpectationValue | None' = None, feedback: 'FeedbackValue | None' = None, issue: 'IssueReferenceValue | None' = None, overrides: 'str | None' = None, valid: 'bool | None' = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __post_init__(self)
|
| __repr__(self)
| Return repr(self).
|
| to_dictionary(self)
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dictionary(d: 'dict[str, Any]') -> "'Assessment'"
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'assessment_id': 'str | None', 'create_time_ms': 'i...
|
| __dataclass_fields__ = {'assessment_id': Field(name='assessment_id',ty...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('name', 'source', 'trace_id', 'run_id', 'rationale',...
|
| assessment_id = None
|
| create_time_ms = None
|
| error = None
|
| expectation = None
|
| feedback = None
|
| issue = None
|
| last_update_time_ms = None
|
| metadata = None
|
| overrides = None
|
| rationale = None
|
| run_id = None
|
| span_id = None
|
| trace_id = None
|
| valid = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class AssessmentError(mlflow.entities._mlflow_object._MlflowObject)
| AssessmentError(error_code: str, error_message: str | None = None, stack_trace: str | None = None) -> None
|
| Error object representing any issues during generating the assessment.
|
| For example, if the LLM-as-a-Judge fails to generate an feedback, you can
| log an error with the error code and message as shown below:
|
| .. code-block:: python
|
| from mlflow.entities import AssessmentError
|
| error = AssessmentError(
| error_code="RATE_LIMIT_EXCEEDED",
| error_message="Rate limit for the judge exceeded.",
| stack_trace="...",
| )
|
| mlflow.log_feedback(
| trace_id="1234",
| name="faithfulness",
| source=AssessmentSourceType.LLM_JUDGE,
| error=error,
| # Skip setting value when an error is present
| )
|
| Args:
| error_code: The error code.
| error_message: The detailed error message. Optional.
| stack_trace: The stack trace of the error. Truncated to 1000 characters
| before being logged to MLflow. Optional.
|
| Method resolution order:
| AssessmentError
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, error_code: str, error_message: str | None = None, stack_trace: str | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| to_dictionary(self)
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dictionary(error_dict)
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'error_code': <class 'str'>, 'error_message': str |...
|
| __dataclass_fields__ = {'error_code': Field(name='error_code',type=<cl...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('error_code', 'error_message', 'stack_trace')
|
| error_message = None
|
| stack_trace = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class AssessmentSource(mlflow.entities._mlflow_object._MlflowObject)
| AssessmentSource(source_type: str, source_id: str = 'default') -> None
|
| Source of an assessment (human, LLM as a judge with GPT-4, etc).
|
| When recording an assessment, MLflow mandates providing a source information
| to keep track of how the assessment is conducted.
|
| Args:
| source_type: The type of the assessment source. Must be one of the values in
| the AssessmentSourceType enum or an instance of the enumerator value.
| source_id: An identifier for the source, e.g. user ID or LLM judge ID. If not
| provided, the default value "default" is used.
|
| Note:
|
| The legacy AssessmentSourceType "AI_JUDGE" is deprecated and will be resolved as
| "LLM_JUDGE". You will receive a warning if using this deprecated value. This legacy
| term will be removed in a future version of MLflow.
|
| Example:
|
| Human annotation can be represented with a source type of "HUMAN":
|
| .. code-block:: python
|
| import mlflow
| from mlflow.entities.assessment import AssessmentSource, AssessmentSourceType
|
| source = AssessmentSource(
| source_type=AssessmentSourceType.HUMAN, # or "HUMAN"
| source_id="bob@example.com",
| )
|
| LLM-as-a-judge can be represented with a source type of "LLM_JUDGE":
|
| .. code-block:: python
|
| import mlflow
| from mlflow.entities.assessment import AssessmentSource, AssessmentSourceType
|
| source = AssessmentSource(
| source_type=AssessmentSourceType.LLM_JUDGE, # or "LLM_JUDGE"
| source_id="gpt-4o-mini",
| )
|
| Heuristic evaluation can be represented with a source type of "CODE":
|
| .. code-block:: python
|
| import mlflow
| from mlflow.entities.assessment import AssessmentSource, AssessmentSourceType
|
| source = AssessmentSource(
| source_type=AssessmentSourceType.CODE, # or "CODE"
| source_id="repo/evaluation_script.py",
| )
|
| To record more context about the assessment, you can use the `metadata` field of
| the assessment logging APIs as well.
|
| Method resolution order:
| AssessmentSource
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, source_type: str, source_id: str = 'default') -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __post_init__(self)
|
| __repr__(self)
| Return repr(self).
|
| to_dictionary(self) -> dict[str, typing.Any]
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dictionary(source_dict: dict[str, typing.Any]) -> 'AssessmentSource'
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'source_id': <class 'str'>, 'source_type': <class '...
|
| __dataclass_fields__ = {'source_id': Field(name='source_id',type=<clas...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('source_type', 'source_id')
|
| source_id = 'default'
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class AssessmentSourceType(builtins.object)
| AssessmentSourceType(source_type: str)
|
| Enumeration and validator for assessment source types.
|
| This class provides constants for valid assessment source types and handles validation
| and standardization of source type values. It supports both direct constant access and
| instance creation with string validation.
|
| The class automatically handles:
| - Case-insensitive string inputs (converts to uppercase)
| - Deprecation warnings for legacy values (AI_JUDGE → LLM_JUDGE)
| - Validation of source type values
|
| Available source types:
| - HUMAN: Assessment performed by a human evaluator
| - LLM_JUDGE: Assessment performed by an LLM-as-a-judge (e.g., GPT-4)
| - CODE: Assessment performed by deterministic code/heuristics
| - SOURCE_TYPE_UNSPECIFIED: Default when source type is not specified
|
| Note:
| The legacy "AI_JUDGE" type is deprecated and automatically converted to "LLM_JUDGE"
| with a deprecation warning. This ensures backward compatibility while encouraging
| migration to the new terminology.
|
| Example:
| Using class constants directly:
|
| .. code-block:: python
|
| from mlflow.entities.assessment import AssessmentSource, AssessmentSourceType
|
| # Direct constant usage
| source = AssessmentSource(source_type=AssessmentSourceType.LLM_JUDGE, source_id="gpt-4")
|
| String validation through instance creation:
|
| .. code-block:: python
|
| # String input - case insensitive
| source = AssessmentSource(
| source_type="llm_judge", # Will be standardized to "LLM_JUDGE"
| source_id="gpt-4",
| )
|
| # Deprecated value - triggers warning
| source = AssessmentSource(
| source_type="AI_JUDGE", # Warning: converts to "LLM_JUDGE"
| source_id="gpt-4",
| )
|
| Methods defined here:
|
| __init__(self, source_type: str)
| Initialize self. See help(type(self)) for accurate signature.
|
| __str__(self)
| Return str(self).
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto_source_type) -> str
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| AI_JUDGE = 'AI_JUDGE'
|
| CODE = 'CODE'
|
| HUMAN = 'HUMAN'
|
| LLM_JUDGE = 'LLM_JUDGE'
|
| SOURCE_TYPE_UNSPECIFIED = 'SOURCE_TYPE_UNSPECIFIED'
class BudgetAction(builtins.str, enum.Enum)
| BudgetAction(*values)
|
| Action to take when a budget is exceeded.
|
| Method resolution order:
| BudgetAction
| builtins.str
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec) from enum.Enum
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__(self) from enum.Enum
| Return str(self).
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| ALERT = <BudgetAction.ALERT: 'ALERT'>
|
| REJECT = <BudgetAction.REJECT: 'REJECT'>
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.str:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(...)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __sizeof__(self, /)
| Return the size of the string in memory, in bytes.
|
| capitalize(self, /)
| Return a capitalized version of the string.
|
| More specifically, make the first character have upper case and the rest lower
| case.
|
| casefold(self, /)
| Return a version of the string suitable for caseless comparisons.
|
| center(self, width, fillchar=' ', /)
| Return a centered string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| count(...)
| S.count(sub[, start[, end]]) -> int
|
| Return the number of non-overlapping occurrences of substring sub in
| string S[start:end]. Optional arguments start and end are
| interpreted as in slice notation.
|
| encode(self, /, encoding='utf-8', errors='strict')
| Encode the string using the codec registered for encoding.
|
| encoding
| The encoding in which to encode the string.
| errors
| The error handling scheme to use for encoding errors.
| The default is 'strict' meaning that encoding errors raise a
| UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
| 'xmlcharrefreplace' as well as any other name registered with
| codecs.register_error that can handle UnicodeEncodeErrors.
|
| endswith(...)
| S.endswith(suffix[, start[, end]]) -> bool
|
| Return True if S ends with the specified suffix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| suffix can also be a tuple of strings to try.
|
| expandtabs(self, /, tabsize=8)
| Return a copy where all tab characters are expanded using spaces.
|
| If tabsize is not given, a tab size of 8 characters is assumed.
|
| find(...)
| S.find(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| format(...)
| S.format(*args, **kwargs) -> str
|
| Return a formatted version of S, using substitutions from args and kwargs.
| The substitutions are identified by braces ('{' and '}').
|
| format_map(...)
| S.format_map(mapping) -> str
|
| Return a formatted version of S, using substitutions from mapping.
| The substitutions are identified by braces ('{' and '}').
|
| index(...)
| S.index(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| isalnum(self, /)
| Return True if the string is an alpha-numeric string, False otherwise.
|
| A string is alpha-numeric if all characters in the string are alpha-numeric and
| there is at least one character in the string.
|
| isalpha(self, /)
| Return True if the string is an alphabetic string, False otherwise.
|
| A string is alphabetic if all characters in the string are alphabetic and there
| is at least one character in the string.
|
| isascii(self, /)
| Return True if all characters in the string are ASCII, False otherwise.
|
| ASCII characters have code points in the range U+0000-U+007F.
| Empty string is ASCII too.
|
| isdecimal(self, /)
| Return True if the string is a decimal string, False otherwise.
|
| A string is a decimal string if all characters in the string are decimal and
| there is at least one character in the string.
|
| isdigit(self, /)
| Return True if the string is a digit string, False otherwise.
|
| A string is a digit string if all characters in the string are digits and there
| is at least one character in the string.
|
| isidentifier(self, /)
| Return True if the string is a valid Python identifier, False otherwise.
|
| Call keyword.iskeyword(s) to test whether string s is a reserved identifier,
| such as "def" or "class".
|
| islower(self, /)
| Return True if the string is a lowercase string, False otherwise.
|
| A string is lowercase if all cased characters in the string are lowercase and
| there is at least one cased character in the string.
|
| isnumeric(self, /)
| Return True if the string is a numeric string, False otherwise.
|
| A string is numeric if all characters in the string are numeric and there is at
| least one character in the string.
|
| isprintable(self, /)
| Return True if the string is printable, False otherwise.
|
| A string is printable if all of its characters are considered printable in
| repr() or if it is empty.
|
| isspace(self, /)
| Return True if the string is a whitespace string, False otherwise.
|
| A string is whitespace if all characters in the string are whitespace and there
| is at least one character in the string.
|
| istitle(self, /)
| Return True if the string is a title-cased string, False otherwise.
|
| In a title-cased string, upper- and title-case characters may only
| follow uncased characters and lowercase characters only cased ones.
|
| isupper(self, /)
| Return True if the string is an uppercase string, False otherwise.
|
| A string is uppercase if all cased characters in the string are uppercase and
| there is at least one cased character in the string.
|
| join(self, iterable, /)
| Concatenate any number of strings.
|
| The string whose method is called is inserted in between each given string.
| The result is returned as a new string.
|
| Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
|
| ljust(self, width, fillchar=' ', /)
| Return a left-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| lower(self, /)
| Return a copy of the string converted to lowercase.
|
| lstrip(self, chars=None, /)
| Return a copy of the string with leading whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| partition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string. If the separator is found,
| returns a 3-tuple containing the part before the separator, the separator
| itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing the original string
| and two empty strings.
|
| removeprefix(self, prefix, /)
| Return a str with the given prefix string removed if present.
|
| If the string starts with the prefix string, return string[len(prefix):].
| Otherwise, return a copy of the original string.
|
| removesuffix(self, suffix, /)
| Return a str with the given suffix string removed if present.
|
| If the string ends with the suffix string and that suffix is not empty,
| return string[:-len(suffix)]. Otherwise, return a copy of the original
| string.
|
| replace(self, old, new, count=-1, /)
| Return a copy with all occurrences of substring old replaced by new.
|
| count
| Maximum number of occurrences to replace.
| -1 (the default value) means replace all occurrences.
|
| If the optional argument count is given, only the first count occurrences are
| replaced.
|
| rfind(...)
| S.rfind(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| rindex(...)
| S.rindex(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| rjust(self, width, fillchar=' ', /)
| Return a right-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| rpartition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string, starting at the end. If
| the separator is found, returns a 3-tuple containing the part before the
| separator, the separator itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing two empty strings
| and the original string.
|
| rsplit(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the end of the string and works to the front.
|
| rstrip(self, chars=None, /)
| Return a copy of the string with trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| split(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the front of the string and works to the end.
|
| Note, str.split() is mainly useful for data that has been intentionally
| delimited. With natural text that includes punctuation, consider using
| the regular expression module.
|
| splitlines(self, /, keepends=False)
| Return a list of the lines in the string, breaking at line boundaries.
|
| Line breaks are not included in the resulting list unless keepends is given and
| true.
|
| startswith(...)
| S.startswith(prefix[, start[, end]]) -> bool
|
| Return True if S starts with the specified prefix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| prefix can also be a tuple of strings to try.
|
| strip(self, chars=None, /)
| Return a copy of the string with leading and trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| swapcase(self, /)
| Convert uppercase characters to lowercase and lowercase characters to uppercase.
|
| title(self, /)
| Return a version of the string where each word is titlecased.
|
| More specifically, words start with uppercased characters and all remaining
| cased characters have lower case.
|
| translate(self, table, /)
| Replace each character in the string using the given translation table.
|
| table
| Translation table, which must be a mapping of Unicode ordinals to
| Unicode ordinals, strings, or None.
|
| The table must implement lookup/indexing via __getitem__, for instance a
| dictionary or list. If this operation raises LookupError, the character is
| left untouched. Characters mapped to None are deleted.
|
| upper(self, /)
| Return a copy of the string converted to uppercase.
|
| zfill(self, width, /)
| Pad a numeric string with zeros on the left, to fill a field of the given width.
|
| The string is never truncated.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.str:
|
| maketrans(...)
| Return a translation table usable for str.translate().
|
| If there is only one argument, it must be a dictionary mapping Unicode
| ordinals (integers) or characters to Unicode ordinals, strings or None.
| Character keys will be then converted to ordinals.
| If there are two arguments, they must be strings of equal length, and
| in the resulting dictionary, each character in x will be mapped to the
| character at the same position in y. If there is a third argument, it
| must be a string, whose characters will be mapped to None in the result.
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class BudgetDuration(builtins.object)
| BudgetDuration(unit: 'BudgetDurationUnit', value: 'int') -> None
|
| Fixed window duration: a (unit, value) pair defining the length of a budget window.
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, unit: 'BudgetDurationUnit', value: 'int') -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __post_init__(self)
|
| __repr__(self)
| Return repr(self).
|
| to_proto(self) -> 'ProtoBudgetDuration'
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto: 'ProtoBudgetDuration') -> 'BudgetDuration'
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'unit': 'BudgetDurationUnit', 'value': 'int'}
|
| __dataclass_fields__ = {'unit': Field(name='unit',type='BudgetDuration...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('unit', 'value')
class BudgetDurationUnit(builtins.str, enum.Enum)
| BudgetDurationUnit(*values)
|
| Duration unit for budget policy fixed windows.
|
| Method resolution order:
| BudgetDurationUnit
| builtins.str
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec) from enum.Enum
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__(self) from enum.Enum
| Return str(self).
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DAYS = <BudgetDurationUnit.DAYS: 'DAYS'>
|
| HOURS = <BudgetDurationUnit.HOURS: 'HOURS'>
|
| MINUTES = <BudgetDurationUnit.MINUTES: 'MINUTES'>
|
| MONTHS = <BudgetDurationUnit.MONTHS: 'MONTHS'>
|
| WEEKS = <BudgetDurationUnit.WEEKS: 'WEEKS'>
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.str:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(...)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __sizeof__(self, /)
| Return the size of the string in memory, in bytes.
|
| capitalize(self, /)
| Return a capitalized version of the string.
|
| More specifically, make the first character have upper case and the rest lower
| case.
|
| casefold(self, /)
| Return a version of the string suitable for caseless comparisons.
|
| center(self, width, fillchar=' ', /)
| Return a centered string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| count(...)
| S.count(sub[, start[, end]]) -> int
|
| Return the number of non-overlapping occurrences of substring sub in
| string S[start:end]. Optional arguments start and end are
| interpreted as in slice notation.
|
| encode(self, /, encoding='utf-8', errors='strict')
| Encode the string using the codec registered for encoding.
|
| encoding
| The encoding in which to encode the string.
| errors
| The error handling scheme to use for encoding errors.
| The default is 'strict' meaning that encoding errors raise a
| UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
| 'xmlcharrefreplace' as well as any other name registered with
| codecs.register_error that can handle UnicodeEncodeErrors.
|
| endswith(...)
| S.endswith(suffix[, start[, end]]) -> bool
|
| Return True if S ends with the specified suffix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| suffix can also be a tuple of strings to try.
|
| expandtabs(self, /, tabsize=8)
| Return a copy where all tab characters are expanded using spaces.
|
| If tabsize is not given, a tab size of 8 characters is assumed.
|
| find(...)
| S.find(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| format(...)
| S.format(*args, **kwargs) -> str
|
| Return a formatted version of S, using substitutions from args and kwargs.
| The substitutions are identified by braces ('{' and '}').
|
| format_map(...)
| S.format_map(mapping) -> str
|
| Return a formatted version of S, using substitutions from mapping.
| The substitutions are identified by braces ('{' and '}').
|
| index(...)
| S.index(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| isalnum(self, /)
| Return True if the string is an alpha-numeric string, False otherwise.
|
| A string is alpha-numeric if all characters in the string are alpha-numeric and
| there is at least one character in the string.
|
| isalpha(self, /)
| Return True if the string is an alphabetic string, False otherwise.
|
| A string is alphabetic if all characters in the string are alphabetic and there
| is at least one character in the string.
|
| isascii(self, /)
| Return True if all characters in the string are ASCII, False otherwise.
|
| ASCII characters have code points in the range U+0000-U+007F.
| Empty string is ASCII too.
|
| isdecimal(self, /)
| Return True if the string is a decimal string, False otherwise.
|
| A string is a decimal string if all characters in the string are decimal and
| there is at least one character in the string.
|
| isdigit(self, /)
| Return True if the string is a digit string, False otherwise.
|
| A string is a digit string if all characters in the string are digits and there
| is at least one character in the string.
|
| isidentifier(self, /)
| Return True if the string is a valid Python identifier, False otherwise.
|
| Call keyword.iskeyword(s) to test whether string s is a reserved identifier,
| such as "def" or "class".
|
| islower(self, /)
| Return True if the string is a lowercase string, False otherwise.
|
| A string is lowercase if all cased characters in the string are lowercase and
| there is at least one cased character in the string.
|
| isnumeric(self, /)
| Return True if the string is a numeric string, False otherwise.
|
| A string is numeric if all characters in the string are numeric and there is at
| least one character in the string.
|
| isprintable(self, /)
| Return True if the string is printable, False otherwise.
|
| A string is printable if all of its characters are considered printable in
| repr() or if it is empty.
|
| isspace(self, /)
| Return True if the string is a whitespace string, False otherwise.
|
| A string is whitespace if all characters in the string are whitespace and there
| is at least one character in the string.
|
| istitle(self, /)
| Return True if the string is a title-cased string, False otherwise.
|
| In a title-cased string, upper- and title-case characters may only
| follow uncased characters and lowercase characters only cased ones.
|
| isupper(self, /)
| Return True if the string is an uppercase string, False otherwise.
|
| A string is uppercase if all cased characters in the string are uppercase and
| there is at least one cased character in the string.
|
| join(self, iterable, /)
| Concatenate any number of strings.
|
| The string whose method is called is inserted in between each given string.
| The result is returned as a new string.
|
| Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
|
| ljust(self, width, fillchar=' ', /)
| Return a left-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| lower(self, /)
| Return a copy of the string converted to lowercase.
|
| lstrip(self, chars=None, /)
| Return a copy of the string with leading whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| partition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string. If the separator is found,
| returns a 3-tuple containing the part before the separator, the separator
| itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing the original string
| and two empty strings.
|
| removeprefix(self, prefix, /)
| Return a str with the given prefix string removed if present.
|
| If the string starts with the prefix string, return string[len(prefix):].
| Otherwise, return a copy of the original string.
|
| removesuffix(self, suffix, /)
| Return a str with the given suffix string removed if present.
|
| If the string ends with the suffix string and that suffix is not empty,
| return string[:-len(suffix)]. Otherwise, return a copy of the original
| string.
|
| replace(self, old, new, count=-1, /)
| Return a copy with all occurrences of substring old replaced by new.
|
| count
| Maximum number of occurrences to replace.
| -1 (the default value) means replace all occurrences.
|
| If the optional argument count is given, only the first count occurrences are
| replaced.
|
| rfind(...)
| S.rfind(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| rindex(...)
| S.rindex(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| rjust(self, width, fillchar=' ', /)
| Return a right-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| rpartition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string, starting at the end. If
| the separator is found, returns a 3-tuple containing the part before the
| separator, the separator itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing two empty strings
| and the original string.
|
| rsplit(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the end of the string and works to the front.
|
| rstrip(self, chars=None, /)
| Return a copy of the string with trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| split(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the front of the string and works to the end.
|
| Note, str.split() is mainly useful for data that has been intentionally
| delimited. With natural text that includes punctuation, consider using
| the regular expression module.
|
| splitlines(self, /, keepends=False)
| Return a list of the lines in the string, breaking at line boundaries.
|
| Line breaks are not included in the resulting list unless keepends is given and
| true.
|
| startswith(...)
| S.startswith(prefix[, start[, end]]) -> bool
|
| Return True if S starts with the specified prefix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| prefix can also be a tuple of strings to try.
|
| strip(self, chars=None, /)
| Return a copy of the string with leading and trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| swapcase(self, /)
| Convert uppercase characters to lowercase and lowercase characters to uppercase.
|
| title(self, /)
| Return a version of the string where each word is titlecased.
|
| More specifically, words start with uppercased characters and all remaining
| cased characters have lower case.
|
| translate(self, table, /)
| Replace each character in the string using the given translation table.
|
| table
| Translation table, which must be a mapping of Unicode ordinals to
| Unicode ordinals, strings, or None.
|
| The table must implement lookup/indexing via __getitem__, for instance a
| dictionary or list. If this operation raises LookupError, the character is
| left untouched. Characters mapped to None are deleted.
|
| upper(self, /)
| Return a copy of the string converted to uppercase.
|
| zfill(self, width, /)
| Pad a numeric string with zeros on the left, to fill a field of the given width.
|
| The string is never truncated.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.str:
|
| maketrans(...)
| Return a translation table usable for str.translate().
|
| If there is only one argument, it must be a dictionary mapping Unicode
| ordinals (integers) or characters to Unicode ordinals, strings or None.
| Character keys will be then converted to ordinals.
| If there are two arguments, they must be strings of equal length, and
| in the resulting dictionary, each character in x will be mapped to the
| character at the same position in y. If there is a third argument, it
| must be a string, whose characters will be mapped to None in the result.
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class BudgetTargetScope(builtins.str, enum.Enum)
| BudgetTargetScope(*values)
|
| Target scope for a budget policy.
|
| Method resolution order:
| BudgetTargetScope
| builtins.str
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec) from enum.Enum
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__(self) from enum.Enum
| Return str(self).
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| ENDPOINT = <BudgetTargetScope.ENDPOINT: 'ENDPOINT'>
|
| GLOBAL = <BudgetTargetScope.GLOBAL: 'GLOBAL'>
|
| WORKSPACE = <BudgetTargetScope.WORKSPACE: 'WORKSPACE'>
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.str:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(...)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __sizeof__(self, /)
| Return the size of the string in memory, in bytes.
|
| capitalize(self, /)
| Return a capitalized version of the string.
|
| More specifically, make the first character have upper case and the rest lower
| case.
|
| casefold(self, /)
| Return a version of the string suitable for caseless comparisons.
|
| center(self, width, fillchar=' ', /)
| Return a centered string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| count(...)
| S.count(sub[, start[, end]]) -> int
|
| Return the number of non-overlapping occurrences of substring sub in
| string S[start:end]. Optional arguments start and end are
| interpreted as in slice notation.
|
| encode(self, /, encoding='utf-8', errors='strict')
| Encode the string using the codec registered for encoding.
|
| encoding
| The encoding in which to encode the string.
| errors
| The error handling scheme to use for encoding errors.
| The default is 'strict' meaning that encoding errors raise a
| UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
| 'xmlcharrefreplace' as well as any other name registered with
| codecs.register_error that can handle UnicodeEncodeErrors.
|
| endswith(...)
| S.endswith(suffix[, start[, end]]) -> bool
|
| Return True if S ends with the specified suffix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| suffix can also be a tuple of strings to try.
|
| expandtabs(self, /, tabsize=8)
| Return a copy where all tab characters are expanded using spaces.
|
| If tabsize is not given, a tab size of 8 characters is assumed.
|
| find(...)
| S.find(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| format(...)
| S.format(*args, **kwargs) -> str
|
| Return a formatted version of S, using substitutions from args and kwargs.
| The substitutions are identified by braces ('{' and '}').
|
| format_map(...)
| S.format_map(mapping) -> str
|
| Return a formatted version of S, using substitutions from mapping.
| The substitutions are identified by braces ('{' and '}').
|
| index(...)
| S.index(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| isalnum(self, /)
| Return True if the string is an alpha-numeric string, False otherwise.
|
| A string is alpha-numeric if all characters in the string are alpha-numeric and
| there is at least one character in the string.
|
| isalpha(self, /)
| Return True if the string is an alphabetic string, False otherwise.
|
| A string is alphabetic if all characters in the string are alphabetic and there
| is at least one character in the string.
|
| isascii(self, /)
| Return True if all characters in the string are ASCII, False otherwise.
|
| ASCII characters have code points in the range U+0000-U+007F.
| Empty string is ASCII too.
|
| isdecimal(self, /)
| Return True if the string is a decimal string, False otherwise.
|
| A string is a decimal string if all characters in the string are decimal and
| there is at least one character in the string.
|
| isdigit(self, /)
| Return True if the string is a digit string, False otherwise.
|
| A string is a digit string if all characters in the string are digits and there
| is at least one character in the string.
|
| isidentifier(self, /)
| Return True if the string is a valid Python identifier, False otherwise.
|
| Call keyword.iskeyword(s) to test whether string s is a reserved identifier,
| such as "def" or "class".
|
| islower(self, /)
| Return True if the string is a lowercase string, False otherwise.
|
| A string is lowercase if all cased characters in the string are lowercase and
| there is at least one cased character in the string.
|
| isnumeric(self, /)
| Return True if the string is a numeric string, False otherwise.
|
| A string is numeric if all characters in the string are numeric and there is at
| least one character in the string.
|
| isprintable(self, /)
| Return True if the string is printable, False otherwise.
|
| A string is printable if all of its characters are considered printable in
| repr() or if it is empty.
|
| isspace(self, /)
| Return True if the string is a whitespace string, False otherwise.
|
| A string is whitespace if all characters in the string are whitespace and there
| is at least one character in the string.
|
| istitle(self, /)
| Return True if the string is a title-cased string, False otherwise.
|
| In a title-cased string, upper- and title-case characters may only
| follow uncased characters and lowercase characters only cased ones.
|
| isupper(self, /)
| Return True if the string is an uppercase string, False otherwise.
|
| A string is uppercase if all cased characters in the string are uppercase and
| there is at least one cased character in the string.
|
| join(self, iterable, /)
| Concatenate any number of strings.
|
| The string whose method is called is inserted in between each given string.
| The result is returned as a new string.
|
| Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
|
| ljust(self, width, fillchar=' ', /)
| Return a left-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| lower(self, /)
| Return a copy of the string converted to lowercase.
|
| lstrip(self, chars=None, /)
| Return a copy of the string with leading whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| partition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string. If the separator is found,
| returns a 3-tuple containing the part before the separator, the separator
| itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing the original string
| and two empty strings.
|
| removeprefix(self, prefix, /)
| Return a str with the given prefix string removed if present.
|
| If the string starts with the prefix string, return string[len(prefix):].
| Otherwise, return a copy of the original string.
|
| removesuffix(self, suffix, /)
| Return a str with the given suffix string removed if present.
|
| If the string ends with the suffix string and that suffix is not empty,
| return string[:-len(suffix)]. Otherwise, return a copy of the original
| string.
|
| replace(self, old, new, count=-1, /)
| Return a copy with all occurrences of substring old replaced by new.
|
| count
| Maximum number of occurrences to replace.
| -1 (the default value) means replace all occurrences.
|
| If the optional argument count is given, only the first count occurrences are
| replaced.
|
| rfind(...)
| S.rfind(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| rindex(...)
| S.rindex(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| rjust(self, width, fillchar=' ', /)
| Return a right-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| rpartition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string, starting at the end. If
| the separator is found, returns a 3-tuple containing the part before the
| separator, the separator itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing two empty strings
| and the original string.
|
| rsplit(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the end of the string and works to the front.
|
| rstrip(self, chars=None, /)
| Return a copy of the string with trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| split(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the front of the string and works to the end.
|
| Note, str.split() is mainly useful for data that has been intentionally
| delimited. With natural text that includes punctuation, consider using
| the regular expression module.
|
| splitlines(self, /, keepends=False)
| Return a list of the lines in the string, breaking at line boundaries.
|
| Line breaks are not included in the resulting list unless keepends is given and
| true.
|
| startswith(...)
| S.startswith(prefix[, start[, end]]) -> bool
|
| Return True if S starts with the specified prefix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| prefix can also be a tuple of strings to try.
|
| strip(self, chars=None, /)
| Return a copy of the string with leading and trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| swapcase(self, /)
| Convert uppercase characters to lowercase and lowercase characters to uppercase.
|
| title(self, /)
| Return a version of the string where each word is titlecased.
|
| More specifically, words start with uppercased characters and all remaining
| cased characters have lower case.
|
| translate(self, table, /)
| Replace each character in the string using the given translation table.
|
| table
| Translation table, which must be a mapping of Unicode ordinals to
| Unicode ordinals, strings, or None.
|
| The table must implement lookup/indexing via __getitem__, for instance a
| dictionary or list. If this operation raises LookupError, the character is
| left untouched. Characters mapped to None are deleted.
|
| upper(self, /)
| Return a copy of the string converted to uppercase.
|
| zfill(self, width, /)
| Pad a numeric string with zeros on the left, to fill a field of the given width.
|
| The string is never truncated.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.str:
|
| maketrans(...)
| Return a translation table usable for str.translate().
|
| If there is only one argument, it must be a dictionary mapping Unicode
| ordinals (integers) or characters to Unicode ordinals, strings or None.
| Character keys will be then converted to ordinals.
| If there are two arguments, they must be strings of equal length, and
| in the resulting dictionary, each character in x will be mapped to the
| character at the same position in y. If there is a third argument, it
| must be a string, whose characters will be mapped to None in the result.
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class BudgetUnit(builtins.str, enum.Enum)
| BudgetUnit(*values)
|
| Budget measurement unit.
|
| Method resolution order:
| BudgetUnit
| builtins.str
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec) from enum.Enum
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__(self) from enum.Enum
| Return str(self).
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| USD = <BudgetUnit.USD: 'USD'>
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.str:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(...)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __sizeof__(self, /)
| Return the size of the string in memory, in bytes.
|
| capitalize(self, /)
| Return a capitalized version of the string.
|
| More specifically, make the first character have upper case and the rest lower
| case.
|
| casefold(self, /)
| Return a version of the string suitable for caseless comparisons.
|
| center(self, width, fillchar=' ', /)
| Return a centered string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| count(...)
| S.count(sub[, start[, end]]) -> int
|
| Return the number of non-overlapping occurrences of substring sub in
| string S[start:end]. Optional arguments start and end are
| interpreted as in slice notation.
|
| encode(self, /, encoding='utf-8', errors='strict')
| Encode the string using the codec registered for encoding.
|
| encoding
| The encoding in which to encode the string.
| errors
| The error handling scheme to use for encoding errors.
| The default is 'strict' meaning that encoding errors raise a
| UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
| 'xmlcharrefreplace' as well as any other name registered with
| codecs.register_error that can handle UnicodeEncodeErrors.
|
| endswith(...)
| S.endswith(suffix[, start[, end]]) -> bool
|
| Return True if S ends with the specified suffix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| suffix can also be a tuple of strings to try.
|
| expandtabs(self, /, tabsize=8)
| Return a copy where all tab characters are expanded using spaces.
|
| If tabsize is not given, a tab size of 8 characters is assumed.
|
| find(...)
| S.find(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| format(...)
| S.format(*args, **kwargs) -> str
|
| Return a formatted version of S, using substitutions from args and kwargs.
| The substitutions are identified by braces ('{' and '}').
|
| format_map(...)
| S.format_map(mapping) -> str
|
| Return a formatted version of S, using substitutions from mapping.
| The substitutions are identified by braces ('{' and '}').
|
| index(...)
| S.index(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| isalnum(self, /)
| Return True if the string is an alpha-numeric string, False otherwise.
|
| A string is alpha-numeric if all characters in the string are alpha-numeric and
| there is at least one character in the string.
|
| isalpha(self, /)
| Return True if the string is an alphabetic string, False otherwise.
|
| A string is alphabetic if all characters in the string are alphabetic and there
| is at least one character in the string.
|
| isascii(self, /)
| Return True if all characters in the string are ASCII, False otherwise.
|
| ASCII characters have code points in the range U+0000-U+007F.
| Empty string is ASCII too.
|
| isdecimal(self, /)
| Return True if the string is a decimal string, False otherwise.
|
| A string is a decimal string if all characters in the string are decimal and
| there is at least one character in the string.
|
| isdigit(self, /)
| Return True if the string is a digit string, False otherwise.
|
| A string is a digit string if all characters in the string are digits and there
| is at least one character in the string.
|
| isidentifier(self, /)
| Return True if the string is a valid Python identifier, False otherwise.
|
| Call keyword.iskeyword(s) to test whether string s is a reserved identifier,
| such as "def" or "class".
|
| islower(self, /)
| Return True if the string is a lowercase string, False otherwise.
|
| A string is lowercase if all cased characters in the string are lowercase and
| there is at least one cased character in the string.
|
| isnumeric(self, /)
| Return True if the string is a numeric string, False otherwise.
|
| A string is numeric if all characters in the string are numeric and there is at
| least one character in the string.
|
| isprintable(self, /)
| Return True if the string is printable, False otherwise.
|
| A string is printable if all of its characters are considered printable in
| repr() or if it is empty.
|
| isspace(self, /)
| Return True if the string is a whitespace string, False otherwise.
|
| A string is whitespace if all characters in the string are whitespace and there
| is at least one character in the string.
|
| istitle(self, /)
| Return True if the string is a title-cased string, False otherwise.
|
| In a title-cased string, upper- and title-case characters may only
| follow uncased characters and lowercase characters only cased ones.
|
| isupper(self, /)
| Return True if the string is an uppercase string, False otherwise.
|
| A string is uppercase if all cased characters in the string are uppercase and
| there is at least one cased character in the string.
|
| join(self, iterable, /)
| Concatenate any number of strings.
|
| The string whose method is called is inserted in between each given string.
| The result is returned as a new string.
|
| Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
|
| ljust(self, width, fillchar=' ', /)
| Return a left-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| lower(self, /)
| Return a copy of the string converted to lowercase.
|
| lstrip(self, chars=None, /)
| Return a copy of the string with leading whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| partition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string. If the separator is found,
| returns a 3-tuple containing the part before the separator, the separator
| itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing the original string
| and two empty strings.
|
| removeprefix(self, prefix, /)
| Return a str with the given prefix string removed if present.
|
| If the string starts with the prefix string, return string[len(prefix):].
| Otherwise, return a copy of the original string.
|
| removesuffix(self, suffix, /)
| Return a str with the given suffix string removed if present.
|
| If the string ends with the suffix string and that suffix is not empty,
| return string[:-len(suffix)]. Otherwise, return a copy of the original
| string.
|
| replace(self, old, new, count=-1, /)
| Return a copy with all occurrences of substring old replaced by new.
|
| count
| Maximum number of occurrences to replace.
| -1 (the default value) means replace all occurrences.
|
| If the optional argument count is given, only the first count occurrences are
| replaced.
|
| rfind(...)
| S.rfind(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| rindex(...)
| S.rindex(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| rjust(self, width, fillchar=' ', /)
| Return a right-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| rpartition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string, starting at the end. If
| the separator is found, returns a 3-tuple containing the part before the
| separator, the separator itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing two empty strings
| and the original string.
|
| rsplit(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the end of the string and works to the front.
|
| rstrip(self, chars=None, /)
| Return a copy of the string with trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| split(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the front of the string and works to the end.
|
| Note, str.split() is mainly useful for data that has been intentionally
| delimited. With natural text that includes punctuation, consider using
| the regular expression module.
|
| splitlines(self, /, keepends=False)
| Return a list of the lines in the string, breaking at line boundaries.
|
| Line breaks are not included in the resulting list unless keepends is given and
| true.
|
| startswith(...)
| S.startswith(prefix[, start[, end]]) -> bool
|
| Return True if S starts with the specified prefix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| prefix can also be a tuple of strings to try.
|
| strip(self, chars=None, /)
| Return a copy of the string with leading and trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| swapcase(self, /)
| Convert uppercase characters to lowercase and lowercase characters to uppercase.
|
| title(self, /)
| Return a version of the string where each word is titlecased.
|
| More specifically, words start with uppercased characters and all remaining
| cased characters have lower case.
|
| translate(self, table, /)
| Replace each character in the string using the given translation table.
|
| table
| Translation table, which must be a mapping of Unicode ordinals to
| Unicode ordinals, strings, or None.
|
| The table must implement lookup/indexing via __getitem__, for instance a
| dictionary or list. If this operation raises LookupError, the character is
| left untouched. Characters mapped to None are deleted.
|
| upper(self, /)
| Return a copy of the string converted to uppercase.
|
| zfill(self, width, /)
| Pad a numeric string with zeros on the left, to fill a field of the given width.
|
| The string is never truncated.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.str:
|
| maketrans(...)
| Return a translation table usable for str.translate().
|
| If there is only one argument, it must be a dictionary mapping Unicode
| ordinals (integers) or characters to Unicode ordinals, strings or None.
| Character keys will be then converted to ordinals.
| If there are two arguments, they must be strings of equal length, and
| in the resulting dictionary, each character in x will be mapped to the
| character at the same position in y. If there is a third argument, it
| must be a string, whose characters will be mapped to None in the result.
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class ConnectOptionSettings(builtins.object)
| ConnectOptionSettings(hidden: 'bool' = False) -> None
|
| .. Note:: Experimental: This class may change or be removed in a future release without warning.
|
| ConnectOptionSettings(hidden: 'bool' = False)
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, hidden: 'bool' = False) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'hidden': 'bool'}
|
| __dataclass_fields__ = {'hidden': Field(name='hidden',type='bool',defa...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('hidden',)
|
| hidden = False
class Dataset(mlflow.entities._mlflow_object._MlflowObject)
| Dataset(name: str, digest: str, source_type: str, source: str, schema: str | None = None, profile: str | None = None) -> None
|
| Dataset object associated with an experiment.
|
| Method resolution order:
| Dataset
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other: mlflow.entities._mlflow_object._MlflowObject) -> bool
| Return self==value.
|
| __init__(self, name: str, digest: str, source_type: str, source: str, schema: str | None = None, profile: str | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| to_dictionary(self)
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| digest
| String digest of the dataset.
|
| name
| String name of the dataset.
|
| profile
| String profile of the dataset.
|
| schema
| String schema of the dataset.
|
| source
| String source of the dataset.
|
| source_type
| String source_type of the dataset.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class DatasetInput(mlflow.entities._mlflow_object._MlflowObject)
| DatasetInput(dataset: mlflow.entities.dataset.Dataset, tags: list[mlflow.entities.input_tag.InputTag] | None = None) -> None
|
| DatasetInput object associated with an experiment.
|
| Method resolution order:
| DatasetInput
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other: mlflow.entities._mlflow_object._MlflowObject) -> bool
| Return self==value.
|
| __init__(self, dataset: mlflow.entities.dataset.Dataset, tags: list[mlflow.entities.input_tag.InputTag] | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| to_dictionary(self)
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| dataset
| Dataset.
|
| tags
| Array of input tags.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class DatasetRecord(mlflow.entities._mlflow_object._MlflowObject)
| DatasetRecord(dataset_id: 'str', inputs: 'dict[str, Any]', dataset_record_id: 'str', created_time: 'int', last_update_time: 'int', outputs: 'dict[str, Any] | None' = None, expectations: 'dict[str, Any] | None' = None, tags: 'dict[str, str] | None' = None, source: 'DatasetRecordSource | None' = None, source_id: 'str | None' = None, source_type: 'str | None' = None, created_by: 'str | None' = None, last_updated_by: 'str | None' = None) -> None
|
| Represents a single record in an evaluation dataset.
|
| A DatasetRecord contains the input data, expected outputs (ground truth),
| and metadata for a single evaluation example. Records are immutable once
| created and are uniquely identified by their dataset_record_id.
|
| Method resolution order:
| DatasetRecord
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other: 'object') -> 'bool'
| Return self==value.
|
| __init__(self, dataset_id: 'str', inputs: 'dict[str, Any]', dataset_record_id: 'str', created_time: 'int', last_update_time: 'int', outputs: 'dict[str, Any] | None' = None, expectations: 'dict[str, Any] | None' = None, tags: 'dict[str, str] | None' = None, source: 'DatasetRecordSource | None' = None, source_id: 'str | None' = None, source_type: 'str | None' = None, created_by: 'str | None' = None, last_updated_by: 'str | None' = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __post_init__(self)
|
| __repr__(self)
| Return repr(self).
|
| to_dict(self) -> 'dict[str, Any]'
|
| to_proto(self) -> 'ProtoDatasetRecord'
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dict(data: 'dict[str, Any]') -> "'DatasetRecord'"
|
| from_proto(proto: 'ProtoDatasetRecord') -> "'DatasetRecord'"
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'created_by': 'str | None', 'created_time': 'int', ...
|
| __dataclass_fields__ = {'created_by': Field(name='created_by',type='st...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('dataset_id', 'inputs', 'dataset_record_id', 'create...
|
| created_by = None
|
| expectations = None
|
| last_updated_by = None
|
| outputs = None
|
| source = None
|
| source_id = None
|
| source_type = None
|
| tags = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class DatasetRecordSource(mlflow.entities._mlflow_object._MlflowObject)
| DatasetRecordSource(source_type: 'DatasetRecordSourceType', source_data: 'dict[str, Any] | None' = None) -> None
|
| Source of a dataset record.
|
| Args:
| source_type: The type of the dataset record source. Must be one of the values in
| the DatasetRecordSourceType enum or a string that can be parsed to one.
| source_data: Additional source-specific data as a dictionary.
|
| Method resolution order:
| DatasetRecordSource
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, source_type: 'DatasetRecordSourceType', source_data: 'dict[str, Any] | None' = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __post_init__(self)
|
| __repr__(self)
| Return repr(self).
|
| to_dict(self) -> 'dict[str, Any]'
|
| to_proto(self) -> 'ProtoDatasetRecordSource'
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dict(data: 'dict[str, Any]') -> "'DatasetRecordSource'"
|
| from_proto(proto: 'ProtoDatasetRecordSource') -> "'DatasetRecordSource'"
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'source_data': 'dict[str, Any] | None', 'source_typ...
|
| __dataclass_fields__ = {'source_data': Field(name='source_data',type='...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('source_type', 'source_data')
|
| source_data = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class DatasetRecordSourceType(builtins.str, enum.Enum)
| DatasetRecordSourceType(*values)
|
| Enumeration for dataset record source types.
|
| Available source types:
| - UNSPECIFIED: Default when source type is not specified
| - TRACE: Record created from a trace/span
| - HUMAN: Record created from human annotation
| - DOCUMENT: Record created from a document
| - CODE: Record created from code/computation
|
| Example:
| Using enum values directly:
|
| .. code-block:: python
|
| from mlflow.entities import DatasetRecordSource, DatasetRecordSourceType
|
| # Direct enum usage
| source = DatasetRecordSource(
| source_type=DatasetRecordSourceType.TRACE, source_data={"trace_id": "trace123"}
| )
|
| String validation through instance creation:
|
| .. code-block:: python
|
| # String input - case insensitive
| source = DatasetRecordSource(
| source_type="trace", # Will be standardized to "TRACE"
| source_data={"trace_id": "trace123"},
| )
|
| Method resolution order:
| DatasetRecordSourceType
| builtins.str
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec) from enum.Enum
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__(self) from enum.Enum
| Return str(self).
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| CODE = <DatasetRecordSourceType.CODE: 'CODE'>
|
| DOCUMENT = <DatasetRecordSourceType.DOCUMENT: 'DOCUMENT'>
|
| HUMAN = <DatasetRecordSourceType.HUMAN: 'HUMAN'>
|
| TRACE = <DatasetRecordSourceType.TRACE: 'TRACE'>
|
| UNSPECIFIED = <DatasetRecordSourceType.UNSPECIFIED: 'UNSPECIFIED'>
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.str:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(...)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __sizeof__(self, /)
| Return the size of the string in memory, in bytes.
|
| capitalize(self, /)
| Return a capitalized version of the string.
|
| More specifically, make the first character have upper case and the rest lower
| case.
|
| casefold(self, /)
| Return a version of the string suitable for caseless comparisons.
|
| center(self, width, fillchar=' ', /)
| Return a centered string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| count(...)
| S.count(sub[, start[, end]]) -> int
|
| Return the number of non-overlapping occurrences of substring sub in
| string S[start:end]. Optional arguments start and end are
| interpreted as in slice notation.
|
| encode(self, /, encoding='utf-8', errors='strict')
| Encode the string using the codec registered for encoding.
|
| encoding
| The encoding in which to encode the string.
| errors
| The error handling scheme to use for encoding errors.
| The default is 'strict' meaning that encoding errors raise a
| UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
| 'xmlcharrefreplace' as well as any other name registered with
| codecs.register_error that can handle UnicodeEncodeErrors.
|
| endswith(...)
| S.endswith(suffix[, start[, end]]) -> bool
|
| Return True if S ends with the specified suffix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| suffix can also be a tuple of strings to try.
|
| expandtabs(self, /, tabsize=8)
| Return a copy where all tab characters are expanded using spaces.
|
| If tabsize is not given, a tab size of 8 characters is assumed.
|
| find(...)
| S.find(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| format(...)
| S.format(*args, **kwargs) -> str
|
| Return a formatted version of S, using substitutions from args and kwargs.
| The substitutions are identified by braces ('{' and '}').
|
| format_map(...)
| S.format_map(mapping) -> str
|
| Return a formatted version of S, using substitutions from mapping.
| The substitutions are identified by braces ('{' and '}').
|
| index(...)
| S.index(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| isalnum(self, /)
| Return True if the string is an alpha-numeric string, False otherwise.
|
| A string is alpha-numeric if all characters in the string are alpha-numeric and
| there is at least one character in the string.
|
| isalpha(self, /)
| Return True if the string is an alphabetic string, False otherwise.
|
| A string is alphabetic if all characters in the string are alphabetic and there
| is at least one character in the string.
|
| isascii(self, /)
| Return True if all characters in the string are ASCII, False otherwise.
|
| ASCII characters have code points in the range U+0000-U+007F.
| Empty string is ASCII too.
|
| isdecimal(self, /)
| Return True if the string is a decimal string, False otherwise.
|
| A string is a decimal string if all characters in the string are decimal and
| there is at least one character in the string.
|
| isdigit(self, /)
| Return True if the string is a digit string, False otherwise.
|
| A string is a digit string if all characters in the string are digits and there
| is at least one character in the string.
|
| isidentifier(self, /)
| Return True if the string is a valid Python identifier, False otherwise.
|
| Call keyword.iskeyword(s) to test whether string s is a reserved identifier,
| such as "def" or "class".
|
| islower(self, /)
| Return True if the string is a lowercase string, False otherwise.
|
| A string is lowercase if all cased characters in the string are lowercase and
| there is at least one cased character in the string.
|
| isnumeric(self, /)
| Return True if the string is a numeric string, False otherwise.
|
| A string is numeric if all characters in the string are numeric and there is at
| least one character in the string.
|
| isprintable(self, /)
| Return True if the string is printable, False otherwise.
|
| A string is printable if all of its characters are considered printable in
| repr() or if it is empty.
|
| isspace(self, /)
| Return True if the string is a whitespace string, False otherwise.
|
| A string is whitespace if all characters in the string are whitespace and there
| is at least one character in the string.
|
| istitle(self, /)
| Return True if the string is a title-cased string, False otherwise.
|
| In a title-cased string, upper- and title-case characters may only
| follow uncased characters and lowercase characters only cased ones.
|
| isupper(self, /)
| Return True if the string is an uppercase string, False otherwise.
|
| A string is uppercase if all cased characters in the string are uppercase and
| there is at least one cased character in the string.
|
| join(self, iterable, /)
| Concatenate any number of strings.
|
| The string whose method is called is inserted in between each given string.
| The result is returned as a new string.
|
| Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
|
| ljust(self, width, fillchar=' ', /)
| Return a left-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| lower(self, /)
| Return a copy of the string converted to lowercase.
|
| lstrip(self, chars=None, /)
| Return a copy of the string with leading whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| partition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string. If the separator is found,
| returns a 3-tuple containing the part before the separator, the separator
| itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing the original string
| and two empty strings.
|
| removeprefix(self, prefix, /)
| Return a str with the given prefix string removed if present.
|
| If the string starts with the prefix string, return string[len(prefix):].
| Otherwise, return a copy of the original string.
|
| removesuffix(self, suffix, /)
| Return a str with the given suffix string removed if present.
|
| If the string ends with the suffix string and that suffix is not empty,
| return string[:-len(suffix)]. Otherwise, return a copy of the original
| string.
|
| replace(self, old, new, count=-1, /)
| Return a copy with all occurrences of substring old replaced by new.
|
| count
| Maximum number of occurrences to replace.
| -1 (the default value) means replace all occurrences.
|
| If the optional argument count is given, only the first count occurrences are
| replaced.
|
| rfind(...)
| S.rfind(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| rindex(...)
| S.rindex(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| rjust(self, width, fillchar=' ', /)
| Return a right-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| rpartition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string, starting at the end. If
| the separator is found, returns a 3-tuple containing the part before the
| separator, the separator itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing two empty strings
| and the original string.
|
| rsplit(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the end of the string and works to the front.
|
| rstrip(self, chars=None, /)
| Return a copy of the string with trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| split(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the front of the string and works to the end.
|
| Note, str.split() is mainly useful for data that has been intentionally
| delimited. With natural text that includes punctuation, consider using
| the regular expression module.
|
| splitlines(self, /, keepends=False)
| Return a list of the lines in the string, breaking at line boundaries.
|
| Line breaks are not included in the resulting list unless keepends is given and
| true.
|
| startswith(...)
| S.startswith(prefix[, start[, end]]) -> bool
|
| Return True if S starts with the specified prefix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| prefix can also be a tuple of strings to try.
|
| strip(self, chars=None, /)
| Return a copy of the string with leading and trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| swapcase(self, /)
| Convert uppercase characters to lowercase and lowercase characters to uppercase.
|
| title(self, /)
| Return a version of the string where each word is titlecased.
|
| More specifically, words start with uppercased characters and all remaining
| cased characters have lower case.
|
| translate(self, table, /)
| Replace each character in the string using the given translation table.
|
| table
| Translation table, which must be a mapping of Unicode ordinals to
| Unicode ordinals, strings, or None.
|
| The table must implement lookup/indexing via __getitem__, for instance a
| dictionary or list. If this operation raises LookupError, the character is
| left untouched. Characters mapped to None are deleted.
|
| upper(self, /)
| Return a copy of the string converted to uppercase.
|
| zfill(self, width, /)
| Pad a numeric string with zeros on the left, to fill a field of the given width.
|
| The string is never truncated.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.str:
|
| maketrans(...)
| Return a translation table usable for str.translate().
|
| If there is only one argument, it must be a dictionary mapping Unicode
| ordinals (integers) or characters to Unicode ordinals, strings or None.
| Character keys will be then converted to ordinals.
| If there are two arguments, they must be strings of equal length, and
| in the resulting dictionary, each character in x will be mapped to the
| character at the same position in y. If there is a third argument, it
| must be a string, whose characters will be mapped to None in the result.
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class Document(builtins.object)
| Document(page_content: str, metadata: dict[str, typing.Any] = <factory>, id: str | None = None) -> None
|
| An entity used in MLflow Tracing to represent retrieved documents in a RETRIEVER span.
|
| Args:
| page_content: The content of the document.
| metadata: A dictionary of metadata associated with the document.
| id: The ID of the document.
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, page_content: str, metadata: dict[str, typing.Any] = <factory>, id: str | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| to_dict(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_langchain_document(document)
|
| from_llama_index_node_with_score(node_with_score)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'id': str | None, 'metadata': dict[str, typing.Any]...
|
| __dataclass_fields__ = {'id': Field(name='id',type=str | None,default=...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('page_content', 'metadata', 'id')
|
| id = None
class EntityAssociationType(builtins.object)
| Constants for entity types used in the entity_association table.
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| EVALUATION_DATASET = 'evaluation_dataset'
|
| EXPERIMENT = 'experiment'
|
| MODEL = 'model'
|
| PROMPT_VERSION = 'prompt_version'
|
| RUN = 'run'
|
| TRACE = 'trace'
class Expectation(Assessment)
| Expectation(name: 'str', value: 'Any', source: 'AssessmentSource | None' = None, trace_id: 'str | None' = None, metadata: 'dict[str, str] | None' = None, span_id: 'str | None' = None, create_time_ms: 'int | None' = None, last_update_time_ms: 'int | None' = None)
|
| Represents an expectation about the output of an operation, such as the expected response
| that a generative AI application should provide to a particular user query.
|
| Args:
| name: The name of the assessment.
| value: The expected value of the operation. This can be any JSON-serializable value.
| source: The source of the assessment. If not provided, the default source is HUMAN.
| trace_id: The ID of the trace associated with the assessment. If unset, the assessment
| is not associated with any trace yet.
| should be specified.
| metadata: The metadata associated with the assessment.
| span_id: The ID of the span associated with the assessment, if the assessment should
| be associated with a particular span in the trace.
| create_time_ms: The creation time of the assessment in milliseconds. If unset, the
| current time is used.
| last_update_time_ms: The last update time of the assessment in milliseconds.
| If unset, the current time is used.
|
| Example:
|
| .. code-block:: python
|
| from mlflow.entities import AssessmentSource, Expectation
|
| expectation = Expectation(
| name="expected_response",
| value="The capital of France is Paris.",
| source=AssessmentSource(
| source_type=AssessmentSourceType.HUMAN,
| source_id="john@example.com",
| ),
| metadata={"project": "my-project"},
| )
|
| Method resolution order:
| Expectation
| Assessment
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, name: 'str', value: 'Any', source: 'AssessmentSource | None' = None, trace_id: 'str | None' = None, metadata: 'dict[str, str] | None' = None, span_id: 'str | None' = None, create_time_ms: 'int | None' = None, last_update_time_ms: 'int | None' = None)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dictionary(d: 'dict[str, Any]') -> "'Expectation'"
|
| from_proto(proto) -> "'Expectation'"
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| value
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __dataclass_fields__ = {'assessment_id': Field(name='assessment_id',ty...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('name', 'source', 'trace_id', 'run_id', 'rationale',...
|
| ----------------------------------------------------------------------
| Methods inherited from Assessment:
|
| __post_init__(self)
|
| to_dictionary(self)
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Assessment:
|
| assessment_id = None
|
| create_time_ms = None
|
| error = None
|
| expectation = None
|
| feedback = None
|
| issue = None
|
| last_update_time_ms = None
|
| metadata = None
|
| overrides = None
|
| rationale = None
|
| run_id = None
|
| span_id = None
|
| trace_id = None
|
| valid = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class Experiment(mlflow.entities._mlflow_object._MlflowObject)
| Experiment(experiment_id, name, artifact_location, lifecycle_stage, tags=None, creation_time=None, last_update_time=None, workspace=None, trace_location=None, effective_trace_archival_retention=None)
|
| Experiment object.
|
| Method resolution order:
| Experiment
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __init__(self, experiment_id, name, artifact_location, lifecycle_stage, tags=None, creation_time=None, last_update_time=None, workspace=None, trace_location=None, effective_trace_archival_retention=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| artifact_location
| String corresponding to the root artifact URI for the experiment.
|
| creation_time
|
| experiment_id
| String ID of the experiment.
|
| last_update_time
|
| lifecycle_stage
| Lifecycle stage of the experiment. Can either be 'active' or 'deleted'.
|
| name
| String name of the experiment.
|
| tags
| Tags that have been set on the experiment.
|
| workspace
| Workspace that owns the experiment, if known.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| effective_trace_archival_retention
| Effective trace archival retention after applying broader-scope overrides.
|
| trace_location
| Trace storage location, if configured.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DEFAULT_EXPERIMENT_NAME = 'Default'
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class ExperimentTag(mlflow.entities._mlflow_object._MlflowObject)
| ExperimentTag(key, value)
|
| Tag object associated with an experiment.
|
| Method resolution order:
| ExperimentTag
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, key, value)
| Initialize self. See help(type(self)) for accurate signature.
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| key
| String name of the tag.
|
| value
| String value of the tag.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class FallbackConfig(mlflow.entities._mlflow_object._MlflowObject)
| FallbackConfig(strategy: 'FallbackStrategy | None' = None, max_attempts: 'int | None' = None) -> None
|
| Configuration for fallback routing strategy.
|
| Defines how requests should be routed across multiple models when using
| fallback routing. Fallback models are defined via GatewayEndpointModelMapping
| with linkage_type=FALLBACK and ordered by fallback_order.
|
| Args:
| strategy: The fallback strategy to use (e.g., FallbackStrategy.SEQUENTIAL).
| max_attempts: Maximum number of fallback models to try (None = try all).
|
| Method resolution order:
| FallbackConfig
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, strategy: 'FallbackStrategy | None' = None, max_attempts: 'int | None' = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| to_proto(self) -> 'ProtoFallbackConfig'
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto: 'ProtoFallbackConfig') -> "'FallbackConfig'"
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'max_attempts': 'int | None', 'strategy': 'Fallback...
|
| __dataclass_fields__ = {'max_attempts': Field(name='max_attempts',type...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('strategy', 'max_attempts')
|
| max_attempts = None
|
| strategy = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class FallbackStrategy(builtins.str, enum.Enum)
| FallbackStrategy(*values)
|
| Fallback strategy for routing.
|
| Method resolution order:
| FallbackStrategy
| builtins.str
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec) from enum.Enum
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__(self) from enum.Enum
| Return str(self).
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| SEQUENTIAL = <FallbackStrategy.SEQUENTIAL: 'SEQUENTIAL'>
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.str:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(...)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __sizeof__(self, /)
| Return the size of the string in memory, in bytes.
|
| capitalize(self, /)
| Return a capitalized version of the string.
|
| More specifically, make the first character have upper case and the rest lower
| case.
|
| casefold(self, /)
| Return a version of the string suitable for caseless comparisons.
|
| center(self, width, fillchar=' ', /)
| Return a centered string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| count(...)
| S.count(sub[, start[, end]]) -> int
|
| Return the number of non-overlapping occurrences of substring sub in
| string S[start:end]. Optional arguments start and end are
| interpreted as in slice notation.
|
| encode(self, /, encoding='utf-8', errors='strict')
| Encode the string using the codec registered for encoding.
|
| encoding
| The encoding in which to encode the string.
| errors
| The error handling scheme to use for encoding errors.
| The default is 'strict' meaning that encoding errors raise a
| UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
| 'xmlcharrefreplace' as well as any other name registered with
| codecs.register_error that can handle UnicodeEncodeErrors.
|
| endswith(...)
| S.endswith(suffix[, start[, end]]) -> bool
|
| Return True if S ends with the specified suffix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| suffix can also be a tuple of strings to try.
|
| expandtabs(self, /, tabsize=8)
| Return a copy where all tab characters are expanded using spaces.
|
| If tabsize is not given, a tab size of 8 characters is assumed.
|
| find(...)
| S.find(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| format(...)
| S.format(*args, **kwargs) -> str
|
| Return a formatted version of S, using substitutions from args and kwargs.
| The substitutions are identified by braces ('{' and '}').
|
| format_map(...)
| S.format_map(mapping) -> str
|
| Return a formatted version of S, using substitutions from mapping.
| The substitutions are identified by braces ('{' and '}').
|
| index(...)
| S.index(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| isalnum(self, /)
| Return True if the string is an alpha-numeric string, False otherwise.
|
| A string is alpha-numeric if all characters in the string are alpha-numeric and
| there is at least one character in the string.
|
| isalpha(self, /)
| Return True if the string is an alphabetic string, False otherwise.
|
| A string is alphabetic if all characters in the string are alphabetic and there
| is at least one character in the string.
|
| isascii(self, /)
| Return True if all characters in the string are ASCII, False otherwise.
|
| ASCII characters have code points in the range U+0000-U+007F.
| Empty string is ASCII too.
|
| isdecimal(self, /)
| Return True if the string is a decimal string, False otherwise.
|
| A string is a decimal string if all characters in the string are decimal and
| there is at least one character in the string.
|
| isdigit(self, /)
| Return True if the string is a digit string, False otherwise.
|
| A string is a digit string if all characters in the string are digits and there
| is at least one character in the string.
|
| isidentifier(self, /)
| Return True if the string is a valid Python identifier, False otherwise.
|
| Call keyword.iskeyword(s) to test whether string s is a reserved identifier,
| such as "def" or "class".
|
| islower(self, /)
| Return True if the string is a lowercase string, False otherwise.
|
| A string is lowercase if all cased characters in the string are lowercase and
| there is at least one cased character in the string.
|
| isnumeric(self, /)
| Return True if the string is a numeric string, False otherwise.
|
| A string is numeric if all characters in the string are numeric and there is at
| least one character in the string.
|
| isprintable(self, /)
| Return True if the string is printable, False otherwise.
|
| A string is printable if all of its characters are considered printable in
| repr() or if it is empty.
|
| isspace(self, /)
| Return True if the string is a whitespace string, False otherwise.
|
| A string is whitespace if all characters in the string are whitespace and there
| is at least one character in the string.
|
| istitle(self, /)
| Return True if the string is a title-cased string, False otherwise.
|
| In a title-cased string, upper- and title-case characters may only
| follow uncased characters and lowercase characters only cased ones.
|
| isupper(self, /)
| Return True if the string is an uppercase string, False otherwise.
|
| A string is uppercase if all cased characters in the string are uppercase and
| there is at least one cased character in the string.
|
| join(self, iterable, /)
| Concatenate any number of strings.
|
| The string whose method is called is inserted in between each given string.
| The result is returned as a new string.
|
| Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
|
| ljust(self, width, fillchar=' ', /)
| Return a left-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| lower(self, /)
| Return a copy of the string converted to lowercase.
|
| lstrip(self, chars=None, /)
| Return a copy of the string with leading whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| partition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string. If the separator is found,
| returns a 3-tuple containing the part before the separator, the separator
| itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing the original string
| and two empty strings.
|
| removeprefix(self, prefix, /)
| Return a str with the given prefix string removed if present.
|
| If the string starts with the prefix string, return string[len(prefix):].
| Otherwise, return a copy of the original string.
|
| removesuffix(self, suffix, /)
| Return a str with the given suffix string removed if present.
|
| If the string ends with the suffix string and that suffix is not empty,
| return string[:-len(suffix)]. Otherwise, return a copy of the original
| string.
|
| replace(self, old, new, count=-1, /)
| Return a copy with all occurrences of substring old replaced by new.
|
| count
| Maximum number of occurrences to replace.
| -1 (the default value) means replace all occurrences.
|
| If the optional argument count is given, only the first count occurrences are
| replaced.
|
| rfind(...)
| S.rfind(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| rindex(...)
| S.rindex(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| rjust(self, width, fillchar=' ', /)
| Return a right-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| rpartition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string, starting at the end. If
| the separator is found, returns a 3-tuple containing the part before the
| separator, the separator itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing two empty strings
| and the original string.
|
| rsplit(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the end of the string and works to the front.
|
| rstrip(self, chars=None, /)
| Return a copy of the string with trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| split(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the front of the string and works to the end.
|
| Note, str.split() is mainly useful for data that has been intentionally
| delimited. With natural text that includes punctuation, consider using
| the regular expression module.
|
| splitlines(self, /, keepends=False)
| Return a list of the lines in the string, breaking at line boundaries.
|
| Line breaks are not included in the resulting list unless keepends is given and
| true.
|
| startswith(...)
| S.startswith(prefix[, start[, end]]) -> bool
|
| Return True if S starts with the specified prefix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| prefix can also be a tuple of strings to try.
|
| strip(self, chars=None, /)
| Return a copy of the string with leading and trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| swapcase(self, /)
| Convert uppercase characters to lowercase and lowercase characters to uppercase.
|
| title(self, /)
| Return a version of the string where each word is titlecased.
|
| More specifically, words start with uppercased characters and all remaining
| cased characters have lower case.
|
| translate(self, table, /)
| Replace each character in the string using the given translation table.
|
| table
| Translation table, which must be a mapping of Unicode ordinals to
| Unicode ordinals, strings, or None.
|
| The table must implement lookup/indexing via __getitem__, for instance a
| dictionary or list. If this operation raises LookupError, the character is
| left untouched. Characters mapped to None are deleted.
|
| upper(self, /)
| Return a copy of the string converted to uppercase.
|
| zfill(self, width, /)
| Pad a numeric string with zeros on the left, to fill a field of the given width.
|
| The string is never truncated.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.str:
|
| maketrans(...)
| Return a translation table usable for str.translate().
|
| If there is only one argument, it must be a dictionary mapping Unicode
| ordinals (integers) or characters to Unicode ordinals, strings or None.
| Character keys will be then converted to ordinals.
| If there are two arguments, they must be strings of equal length, and
| in the resulting dictionary, each character in x will be mapped to the
| character at the same position in y. If there is a third argument, it
| must be a string, whose characters will be mapped to None in the result.
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class Feedback(Assessment)
| Feedback(name: 'str' = 'feedback', value: 'FeedbackValueType | None' = None, error: 'Exception | AssessmentError | str | None' = None, source: 'AssessmentSource | None' = None, trace_id: 'str | None' = None, metadata: 'dict[str, str] | None' = None, span_id: 'str | None' = None, create_time_ms: 'int | None' = None, last_update_time_ms: 'int | None' = None, rationale: 'str | None' = None, overrides: 'str | None' = None, valid: 'bool' = True)
|
| Represents feedback about the output of an operation. For example, if the response from a
| generative AI application to a particular user query is correct, then a human or LLM judge
| may provide feedback with the value ``"correct"``.
|
| Args:
| name: The name of the assessment. If not provided, the default name "feedback" is used.
| value: The feedback value. This can be one of the following types:
| - float
| - int
| - str
| - bool
| - list of values of the same types as above
| - dict with string keys and values of the same types as above
| error: An optional error associated with the feedback. This is used to indicate
| that the feedback is not valid or cannot be processed. Accepts an exception
| object, or an :py:class:`~mlflow.entities.Expectation` object.
| rationale: The rationale / justification for the feedback.
| source: The source of the assessment. If not provided, the default source is CODE.
| trace_id: The ID of the trace associated with the assessment. If unset, the assessment
| is not associated with any trace yet.
| should be specified.
| metadata: The metadata associated with the assessment.
| span_id: The ID of the span associated with the assessment, if the assessment should
| be associated with a particular span in the trace.
| create_time_ms: The creation time of the assessment in milliseconds. If unset, the
| current time is used.
| last_update_time_ms: The last update time of the assessment in milliseconds.
| If unset, the current time is used.
|
| Example:
|
| .. code-block:: python
|
| from mlflow.entities import AssessmentSource, Feedback
|
| feedback = Feedback(
| name="correctness",
| value=True,
| rationale="The response is correct.",
| source=AssessmentSource(
| source_type="HUMAN",
| source_id="john@example.com",
| ),
| metadata={"project": "my-project"},
| )
|
| Method resolution order:
| Feedback
| Assessment
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, name: 'str' = 'feedback', value: 'FeedbackValueType | None' = None, error: 'Exception | AssessmentError | str | None' = None, source: 'AssessmentSource | None' = None, trace_id: 'str | None' = None, metadata: 'dict[str, str] | None' = None, span_id: 'str | None' = None, create_time_ms: 'int | None' = None, last_update_time_ms: 'int | None' = None, rationale: 'str | None' = None, overrides: 'str | None' = None, valid: 'bool' = True)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dictionary(d: 'dict[str, Any]') -> "'Feedback'"
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| error_code
| The error code of the error that occurred when the feedback was created.
|
| error_message
| The error message of the error that occurred when the feedback was created.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| value
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __dataclass_fields__ = {'assessment_id': Field(name='assessment_id',ty...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('name', 'source', 'trace_id', 'run_id', 'rationale',...
|
| ----------------------------------------------------------------------
| Methods inherited from Assessment:
|
| __post_init__(self)
|
| to_dictionary(self)
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Assessment:
|
| assessment_id = None
|
| create_time_ms = None
|
| error = None
|
| expectation = None
|
| feedback = None
|
| issue = None
|
| last_update_time_ms = None
|
| metadata = None
|
| overrides = None
|
| rationale = None
|
| run_id = None
|
| span_id = None
|
| trace_id = None
|
| valid = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class FileInfo(mlflow.entities._mlflow_object._MlflowObject)
| FileInfo(path, is_dir, file_size)
|
| Metadata about a file or directory.
|
| Method resolution order:
| FileInfo
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, path, is_dir, file_size)
| Initialize self. See help(type(self)) for accurate signature.
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| file_size
| Size of the file or directory. If the FileInfo is a directory, returns None.
|
| is_dir
| Whether the FileInfo corresponds to a directory.
|
| path
| String path of the file or directory.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class GatewayBudgetPolicy(mlflow.entities._mlflow_object._MlflowObject)
| GatewayBudgetPolicy(budget_policy_id: 'str', budget_unit: 'BudgetUnit', budget_amount: 'float', duration: 'BudgetDuration', target_scope: 'BudgetTargetScope', budget_action: 'BudgetAction', created_at: 'int', last_updated_at: 'int', created_by: 'str | None' = None, last_updated_by: 'str | None' = None, workspace: 'str | None' = None, target_value: 'str | None' = None) -> None
|
| Represents a budget policy for the AI Gateway.
|
| Budget policies set limits with fixed time windows,
| supporting global, per-workspace, or per-endpoint scoping.
|
| Args:
| budget_policy_id: Unique identifier for this budget policy.
| budget_unit: Budget measurement unit (e.g. USD).
| budget_amount: Budget limit amount.
| duration: Fixed time window (unit + length pair).
| target_scope: Scope of the budget (GLOBAL, WORKSPACE, or ENDPOINT).
| budget_action: Action when budget is exceeded (ALERT, REJECT).
| created_at: Timestamp (milliseconds) when the policy was created.
| last_updated_at: Timestamp (milliseconds) when the policy was last updated.
| created_by: User ID who created the policy.
| last_updated_by: User ID who last updated the policy.
| workspace: Workspace that owns the policy.
| target_value: Target the policy applies to, interpreted per ``target_scope``:
| a gateway endpoint ID for ENDPOINT scope. ``None`` for GLOBAL and
| WORKSPACE scopes.
|
| Method resolution order:
| GatewayBudgetPolicy
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, budget_policy_id: 'str', budget_unit: 'BudgetUnit', budget_amount: 'float', duration: 'BudgetDuration', target_scope: 'BudgetTargetScope', budget_action: 'BudgetAction', created_at: 'int', last_updated_at: 'int', created_by: 'str | None' = None, last_updated_by: 'str | None' = None, workspace: 'str | None' = None, target_value: 'str | None' = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __post_init__(self)
|
| __repr__(self)
| Return repr(self).
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'budget_action': 'BudgetAction', 'budget_amount': '...
|
| __dataclass_fields__ = {'budget_action': Field(name='budget_action',ty...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('budget_policy_id', 'budget_unit', 'budget_amount', ...
|
| created_by = None
|
| last_updated_by = None
|
| target_value = None
|
| workspace = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class GatewayEndpoint(mlflow.entities._mlflow_object._MlflowObject)
| GatewayEndpoint(endpoint_id: 'str', name: 'str | None', created_at: 'int', last_updated_at: 'int', model_mappings: 'list[GatewayEndpointModelMapping]' = <factory>, tags: "list['GatewayEndpointTag']" = <factory>, created_by: 'str | None' = None, last_updated_by: 'str | None' = None, routing_strategy: 'RoutingStrategy | None' = None, fallback_config: 'FallbackConfig | None' = None, experiment_id: 'str | None' = None, usage_tracking: 'bool' = True, workspace: 'str | None' = None) -> None
|
| Represents an LLM gateway endpoint with its associated model configurations.
|
| Args:
| endpoint_id: Unique identifier for this endpoint.
| name: User-friendly name for the endpoint (optional).
| created_at: Timestamp (milliseconds) when the endpoint was created.
| last_updated_at: Timestamp (milliseconds) when the endpoint was last updated.
| model_mappings: List of model mappings bound to this endpoint.
| tags: List of tags associated with this endpoint.
| created_by: User ID who created the endpoint.
| last_updated_by: User ID who last updated the endpoint.
| routing_strategy: Routing strategy for the endpoint (e.g., "FALLBACK").
| fallback_config: Fallback configuration entity (if routing_strategy is FALLBACK).
| experiment_id: ID of the MLflow experiment where traces for this endpoint are logged.
| usage_tracking: Whether usage tracking is enabled for this endpoint.
| workspace: Workspace that owns the endpoint.
|
| Method resolution order:
| GatewayEndpoint
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, endpoint_id: 'str', name: 'str | None', created_at: 'int', last_updated_at: 'int', model_mappings: 'list[GatewayEndpointModelMapping]' = <factory>, tags: "list['GatewayEndpointTag']" = <factory>, created_by: 'str | None' = None, last_updated_by: 'str | None' = None, routing_strategy: 'RoutingStrategy | None' = None, fallback_config: 'FallbackConfig | None' = None, experiment_id: 'str | None' = None, usage_tracking: 'bool' = True, workspace: 'str | None' = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __post_init__(self)
|
| __repr__(self)
| Return repr(self).
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'created_at': 'int', 'created_by': 'str | None', 'e...
|
| __dataclass_fields__ = {'created_at': Field(name='created_at',type='in...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('endpoint_id', 'name', 'created_at', 'last_updated_a...
|
| created_by = None
|
| experiment_id = None
|
| fallback_config = None
|
| last_updated_by = None
|
| routing_strategy = None
|
| usage_tracking = True
|
| workspace = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class GatewayEndpointBinding(mlflow.entities._mlflow_object._MlflowObject)
| GatewayEndpointBinding(endpoint_id: 'str', resource_type: 'GatewayResourceType', resource_id: 'str', created_at: 'int', last_updated_at: 'int', created_by: 'str | None' = None, last_updated_by: 'str | None' = None, display_name: 'str | None' = None) -> None
|
| Represents a binding between an endpoint and an MLflow resource.
|
| Bindings track which MLflow resources (e.g., scorer jobs) are configured to use
| which endpoints. The composite key (endpoint_id, resource_type, resource_id) uniquely
| identifies each binding.
|
| Args:
| endpoint_id: ID of the endpoint this binding references.
| resource_type: Type of MLflow resource (e.g., "scorer").
| resource_id: ID of the specific resource instance.
| created_at: Timestamp (milliseconds) when the binding was created.
| last_updated_at: Timestamp (milliseconds) when the binding was last updated.
| created_by: User ID who created the binding.
| last_updated_by: User ID who last updated the binding.
| display_name: Human-readable display name for the resource (e.g., scorer name).
|
| Method resolution order:
| GatewayEndpointBinding
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, endpoint_id: 'str', resource_type: 'GatewayResourceType', resource_id: 'str', created_at: 'int', last_updated_at: 'int', created_by: 'str | None' = None, last_updated_by: 'str | None' = None, display_name: 'str | None' = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'created_at': 'int', 'created_by': 'str | None', 'd...
|
| __dataclass_fields__ = {'created_at': Field(name='created_at',type='in...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('endpoint_id', 'resource_type', 'resource_id', 'crea...
|
| created_by = None
|
| display_name = None
|
| last_updated_by = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class GatewayEndpointModelConfig(mlflow.entities._mlflow_object._MlflowObject)
| GatewayEndpointModelConfig(model_definition_id: 'str', linkage_type: 'GatewayModelLinkageType', weight: 'float' = 1.0, fallback_order: 'int | None' = None) -> None
|
| Configuration for a model attached to an endpoint.
|
| This structured object combines all configuration needed to attach a model
| to an endpoint, including the model definition ID, linkage type, weight,
| and fallback order.
|
| Args:
| model_definition_id: ID of the model definition to attach.
| linkage_type: Type of linkage (PRIMARY or FALLBACK).
| weight: Routing weight for traffic distribution (default 1.0).
| fallback_order: Order for fallback attempts (only for FALLBACK linkages, None for PRIMARY).
|
| Method resolution order:
| GatewayEndpointModelConfig
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, model_definition_id: 'str', linkage_type: 'GatewayModelLinkageType', weight: 'float' = 1.0, fallback_order: 'int | None' = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| to_proto(self) -> 'ProtoGatewayEndpointModelConfig'
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto: 'ProtoGatewayEndpointModelConfig') -> "'GatewayEndpointModelConfig'"
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'fallback_order': 'int | None', 'linkage_type': 'Ga...
|
| __dataclass_fields__ = {'fallback_order': Field(name='fallback_order',...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('model_definition_id', 'linkage_type', 'weight', 'fa...
|
| fallback_order = None
|
| weight = 1.0
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class GatewayEndpointModelMapping(mlflow.entities._mlflow_object._MlflowObject)
| GatewayEndpointModelMapping(mapping_id: 'str', endpoint_id: 'str', model_definition_id: 'str', model_definition: 'GatewayModelDefinition | None', weight: 'float', linkage_type: 'GatewayModelLinkageType', fallback_order: 'int | None', created_at: 'int', created_by: 'str | None' = None) -> None
|
| Represents a mapping between an endpoint and a model definition.
|
| This is a junction entity that links endpoints to model definitions,
| enabling many-to-many relationships and traffic routing configuration.
|
| Args:
| mapping_id: Unique identifier for this mapping.
| endpoint_id: ID of the endpoint.
| model_definition_id: ID of the model definition.
| model_definition: The full model definition (populated via JOIN).
| weight: Routing weight for traffic distribution (default 1).
| linkage_type: Type of linkage (PRIMARY or FALLBACK).
| fallback_order: Zero-indexed order for fallback attempts (only for FALLBACK linkages)
| created_at: Timestamp (milliseconds) when the mapping was created.
| created_by: User ID who created the mapping.
|
| Method resolution order:
| GatewayEndpointModelMapping
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, mapping_id: 'str', endpoint_id: 'str', model_definition_id: 'str', model_definition: 'GatewayModelDefinition | None', weight: 'float', linkage_type: 'GatewayModelLinkageType', fallback_order: 'int | None', created_at: 'int', created_by: 'str | None' = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'created_at': 'int', 'created_by': 'str | None', 'e...
|
| __dataclass_fields__ = {'created_at': Field(name='created_at',type='in...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('mapping_id', 'endpoint_id', 'model_definition_id', ...
|
| created_by = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class GatewayEndpointTag(mlflow.entities._mlflow_object._MlflowObject)
| GatewayEndpointTag(key: 'str', value: 'str | None') -> None
|
| Represents a tag (key-value pair) associated with a gateway endpoint.
|
| Tags are used for categorization, filtering, and metadata storage for endpoints.
|
| Args:
| key: Tag key (max 250 characters).
| value: Tag value (max 5000 characters, can be None).
|
| Method resolution order:
| GatewayEndpointTag
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, key: 'str', value: 'str | None') -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'key': 'str', 'value': 'str | None'}
|
| __dataclass_fields__ = {'key': Field(name='key',type='str',default=<da...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('key', 'value')
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class GatewayGuardrail(mlflow.entities._mlflow_object._MlflowObject)
| GatewayGuardrail(guardrail_id: 'str', name: 'str', scorer: 'ScorerVersion', stage: 'GuardrailStage', action: 'GuardrailAction', created_at: 'int', last_updated_at: 'int', action_endpoint_name: 'str | None' = None, created_by: 'str | None' = None, last_updated_by: 'str | None' = None, workspace: 'str | None' = None) -> None
|
| GatewayGuardrail(guardrail_id: 'str', name: 'str', scorer: 'ScorerVersion', stage: 'GuardrailStage', action: 'GuardrailAction', created_at: 'int', last_updated_at: 'int', action_endpoint_name: 'str | None' = None, created_by: 'str | None' = None, last_updated_by: 'str | None' = None, workspace: 'str | None' = None)
|
| Method resolution order:
| GatewayGuardrail
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, guardrail_id: 'str', name: 'str', scorer: 'ScorerVersion', stage: 'GuardrailStage', action: 'GuardrailAction', created_at: 'int', last_updated_at: 'int', action_endpoint_name: 'str | None' = None, created_by: 'str | None' = None, last_updated_by: 'str | None' = None, workspace: 'str | None' = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __post_init__(self)
|
| __repr__(self)
| Return repr(self).
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'action': 'GuardrailAction', 'action_endpoint_name'...
|
| __dataclass_fields__ = {'action': Field(name='action',type='GuardrailA...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('guardrail_id', 'name', 'scorer', 'stage', 'action',...
|
| action_endpoint_name = None
|
| created_by = None
|
| last_updated_by = None
|
| workspace = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class GatewayGuardrailConfig(mlflow.entities._mlflow_object._MlflowObject)
| GatewayGuardrailConfig(endpoint_id: 'str', guardrail_id: 'str', execution_order: 'int | None', created_at: 'int', guardrail: 'GatewayGuardrail | None' = None, created_by: 'str | None' = None, workspace: 'str | None' = None) -> None
|
| Junction between a guardrail and a gateway endpoint, with ordering.
|
| Method resolution order:
| GatewayGuardrailConfig
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, endpoint_id: 'str', guardrail_id: 'str', execution_order: 'int | None', created_at: 'int', guardrail: 'GatewayGuardrail | None' = None, created_by: 'str | None' = None, workspace: 'str | None' = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'created_at': 'int', 'created_by': 'str | None', 'e...
|
| __dataclass_fields__ = {'created_at': Field(name='created_at',type='in...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('endpoint_id', 'guardrail_id', 'execution_order', 'c...
|
| created_by = None
|
| guardrail = None
|
| workspace = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class GatewayModelDefinition(mlflow.entities._mlflow_object._MlflowObject)
| GatewayModelDefinition(model_definition_id: 'str', name: 'str', secret_id: 'str | None', secret_name: 'str | None', provider: 'str', model_name: 'str', created_at: 'int', last_updated_at: 'int', created_by: 'str | None' = None, last_updated_by: 'str | None' = None, workspace: 'str | None' = None) -> None
|
| Represents a reusable LLM model configuration.
|
| Model definitions can be shared across multiple endpoints, enabling
| centralized management of model configurations and API credentials.
|
| Args:
| model_definition_id: Unique identifier for this model definition.
| name: User-friendly name for identification and reuse.
| secret_id: ID of the secret containing authentication credentials (None if orphaned).
| secret_name: Name of the secret for display/reference purposes (None if orphaned).
| provider: LLM provider (e.g., "openai", "anthropic", "cohere", "bedrock").
| model_name: Provider-specific model identifier (e.g., "gpt-4o", "claude-3-5-sonnet").
| created_at: Timestamp (milliseconds) when the model definition was created.
| last_updated_at: Timestamp (milliseconds) when the model definition was last updated.
| created_by: User ID who created the model definition.
| last_updated_by: User ID who last updated the model definition.
| workspace: Workspace that owns the model definition.
|
| Method resolution order:
| GatewayModelDefinition
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, model_definition_id: 'str', name: 'str', secret_id: 'str | None', secret_name: 'str | None', provider: 'str', model_name: 'str', created_at: 'int', last_updated_at: 'int', created_by: 'str | None' = None, last_updated_by: 'str | None' = None, workspace: 'str | None' = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __post_init__(self)
|
| __repr__(self)
| Return repr(self).
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'created_at': 'int', 'created_by': 'str | None', 'l...
|
| __dataclass_fields__ = {'created_at': Field(name='created_at',type='in...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('model_definition_id', 'name', 'secret_id', 'secret_...
|
| created_by = None
|
| last_updated_by = None
|
| workspace = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class GatewayModelLinkageType(builtins.str, enum.Enum)
| GatewayModelLinkageType(*values)
|
| Type of linkage between endpoint and model definition.
|
| Method resolution order:
| GatewayModelLinkageType
| builtins.str
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec) from enum.Enum
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__(self) from enum.Enum
| Return str(self).
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| FALLBACK = <GatewayModelLinkageType.FALLBACK: 'FALLBACK'>
|
| PRIMARY = <GatewayModelLinkageType.PRIMARY: 'PRIMARY'>
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.str:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(...)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __sizeof__(self, /)
| Return the size of the string in memory, in bytes.
|
| capitalize(self, /)
| Return a capitalized version of the string.
|
| More specifically, make the first character have upper case and the rest lower
| case.
|
| casefold(self, /)
| Return a version of the string suitable for caseless comparisons.
|
| center(self, width, fillchar=' ', /)
| Return a centered string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| count(...)
| S.count(sub[, start[, end]]) -> int
|
| Return the number of non-overlapping occurrences of substring sub in
| string S[start:end]. Optional arguments start and end are
| interpreted as in slice notation.
|
| encode(self, /, encoding='utf-8', errors='strict')
| Encode the string using the codec registered for encoding.
|
| encoding
| The encoding in which to encode the string.
| errors
| The error handling scheme to use for encoding errors.
| The default is 'strict' meaning that encoding errors raise a
| UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
| 'xmlcharrefreplace' as well as any other name registered with
| codecs.register_error that can handle UnicodeEncodeErrors.
|
| endswith(...)
| S.endswith(suffix[, start[, end]]) -> bool
|
| Return True if S ends with the specified suffix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| suffix can also be a tuple of strings to try.
|
| expandtabs(self, /, tabsize=8)
| Return a copy where all tab characters are expanded using spaces.
|
| If tabsize is not given, a tab size of 8 characters is assumed.
|
| find(...)
| S.find(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| format(...)
| S.format(*args, **kwargs) -> str
|
| Return a formatted version of S, using substitutions from args and kwargs.
| The substitutions are identified by braces ('{' and '}').
|
| format_map(...)
| S.format_map(mapping) -> str
|
| Return a formatted version of S, using substitutions from mapping.
| The substitutions are identified by braces ('{' and '}').
|
| index(...)
| S.index(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| isalnum(self, /)
| Return True if the string is an alpha-numeric string, False otherwise.
|
| A string is alpha-numeric if all characters in the string are alpha-numeric and
| there is at least one character in the string.
|
| isalpha(self, /)
| Return True if the string is an alphabetic string, False otherwise.
|
| A string is alphabetic if all characters in the string are alphabetic and there
| is at least one character in the string.
|
| isascii(self, /)
| Return True if all characters in the string are ASCII, False otherwise.
|
| ASCII characters have code points in the range U+0000-U+007F.
| Empty string is ASCII too.
|
| isdecimal(self, /)
| Return True if the string is a decimal string, False otherwise.
|
| A string is a decimal string if all characters in the string are decimal and
| there is at least one character in the string.
|
| isdigit(self, /)
| Return True if the string is a digit string, False otherwise.
|
| A string is a digit string if all characters in the string are digits and there
| is at least one character in the string.
|
| isidentifier(self, /)
| Return True if the string is a valid Python identifier, False otherwise.
|
| Call keyword.iskeyword(s) to test whether string s is a reserved identifier,
| such as "def" or "class".
|
| islower(self, /)
| Return True if the string is a lowercase string, False otherwise.
|
| A string is lowercase if all cased characters in the string are lowercase and
| there is at least one cased character in the string.
|
| isnumeric(self, /)
| Return True if the string is a numeric string, False otherwise.
|
| A string is numeric if all characters in the string are numeric and there is at
| least one character in the string.
|
| isprintable(self, /)
| Return True if the string is printable, False otherwise.
|
| A string is printable if all of its characters are considered printable in
| repr() or if it is empty.
|
| isspace(self, /)
| Return True if the string is a whitespace string, False otherwise.
|
| A string is whitespace if all characters in the string are whitespace and there
| is at least one character in the string.
|
| istitle(self, /)
| Return True if the string is a title-cased string, False otherwise.
|
| In a title-cased string, upper- and title-case characters may only
| follow uncased characters and lowercase characters only cased ones.
|
| isupper(self, /)
| Return True if the string is an uppercase string, False otherwise.
|
| A string is uppercase if all cased characters in the string are uppercase and
| there is at least one cased character in the string.
|
| join(self, iterable, /)
| Concatenate any number of strings.
|
| The string whose method is called is inserted in between each given string.
| The result is returned as a new string.
|
| Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
|
| ljust(self, width, fillchar=' ', /)
| Return a left-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| lower(self, /)
| Return a copy of the string converted to lowercase.
|
| lstrip(self, chars=None, /)
| Return a copy of the string with leading whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| partition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string. If the separator is found,
| returns a 3-tuple containing the part before the separator, the separator
| itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing the original string
| and two empty strings.
|
| removeprefix(self, prefix, /)
| Return a str with the given prefix string removed if present.
|
| If the string starts with the prefix string, return string[len(prefix):].
| Otherwise, return a copy of the original string.
|
| removesuffix(self, suffix, /)
| Return a str with the given suffix string removed if present.
|
| If the string ends with the suffix string and that suffix is not empty,
| return string[:-len(suffix)]. Otherwise, return a copy of the original
| string.
|
| replace(self, old, new, count=-1, /)
| Return a copy with all occurrences of substring old replaced by new.
|
| count
| Maximum number of occurrences to replace.
| -1 (the default value) means replace all occurrences.
|
| If the optional argument count is given, only the first count occurrences are
| replaced.
|
| rfind(...)
| S.rfind(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| rindex(...)
| S.rindex(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| rjust(self, width, fillchar=' ', /)
| Return a right-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| rpartition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string, starting at the end. If
| the separator is found, returns a 3-tuple containing the part before the
| separator, the separator itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing two empty strings
| and the original string.
|
| rsplit(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the end of the string and works to the front.
|
| rstrip(self, chars=None, /)
| Return a copy of the string with trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| split(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the front of the string and works to the end.
|
| Note, str.split() is mainly useful for data that has been intentionally
| delimited. With natural text that includes punctuation, consider using
| the regular expression module.
|
| splitlines(self, /, keepends=False)
| Return a list of the lines in the string, breaking at line boundaries.
|
| Line breaks are not included in the resulting list unless keepends is given and
| true.
|
| startswith(...)
| S.startswith(prefix[, start[, end]]) -> bool
|
| Return True if S starts with the specified prefix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| prefix can also be a tuple of strings to try.
|
| strip(self, chars=None, /)
| Return a copy of the string with leading and trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| swapcase(self, /)
| Convert uppercase characters to lowercase and lowercase characters to uppercase.
|
| title(self, /)
| Return a version of the string where each word is titlecased.
|
| More specifically, words start with uppercased characters and all remaining
| cased characters have lower case.
|
| translate(self, table, /)
| Replace each character in the string using the given translation table.
|
| table
| Translation table, which must be a mapping of Unicode ordinals to
| Unicode ordinals, strings, or None.
|
| The table must implement lookup/indexing via __getitem__, for instance a
| dictionary or list. If this operation raises LookupError, the character is
| left untouched. Characters mapped to None are deleted.
|
| upper(self, /)
| Return a copy of the string converted to uppercase.
|
| zfill(self, width, /)
| Pad a numeric string with zeros on the left, to fill a field of the given width.
|
| The string is never truncated.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.str:
|
| maketrans(...)
| Return a translation table usable for str.translate().
|
| If there is only one argument, it must be a dictionary mapping Unicode
| ordinals (integers) or characters to Unicode ordinals, strings or None.
| Character keys will be then converted to ordinals.
| If there are two arguments, they must be strings of equal length, and
| in the resulting dictionary, each character in x will be mapped to the
| character at the same position in y. If there is a third argument, it
| must be a string, whose characters will be mapped to None in the result.
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class GatewayResourceType(builtins.str, enum.Enum)
| GatewayResourceType(*values)
|
| Valid MLflow resource types that can use gateway endpoints.
|
| Method resolution order:
| GatewayResourceType
| builtins.str
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec) from enum.Enum
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__(self) from enum.Enum
| Return str(self).
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| SCORER = <GatewayResourceType.SCORER: 'scorer'>
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.str:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(...)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __sizeof__(self, /)
| Return the size of the string in memory, in bytes.
|
| capitalize(self, /)
| Return a capitalized version of the string.
|
| More specifically, make the first character have upper case and the rest lower
| case.
|
| casefold(self, /)
| Return a version of the string suitable for caseless comparisons.
|
| center(self, width, fillchar=' ', /)
| Return a centered string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| count(...)
| S.count(sub[, start[, end]]) -> int
|
| Return the number of non-overlapping occurrences of substring sub in
| string S[start:end]. Optional arguments start and end are
| interpreted as in slice notation.
|
| encode(self, /, encoding='utf-8', errors='strict')
| Encode the string using the codec registered for encoding.
|
| encoding
| The encoding in which to encode the string.
| errors
| The error handling scheme to use for encoding errors.
| The default is 'strict' meaning that encoding errors raise a
| UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
| 'xmlcharrefreplace' as well as any other name registered with
| codecs.register_error that can handle UnicodeEncodeErrors.
|
| endswith(...)
| S.endswith(suffix[, start[, end]]) -> bool
|
| Return True if S ends with the specified suffix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| suffix can also be a tuple of strings to try.
|
| expandtabs(self, /, tabsize=8)
| Return a copy where all tab characters are expanded using spaces.
|
| If tabsize is not given, a tab size of 8 characters is assumed.
|
| find(...)
| S.find(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| format(...)
| S.format(*args, **kwargs) -> str
|
| Return a formatted version of S, using substitutions from args and kwargs.
| The substitutions are identified by braces ('{' and '}').
|
| format_map(...)
| S.format_map(mapping) -> str
|
| Return a formatted version of S, using substitutions from mapping.
| The substitutions are identified by braces ('{' and '}').
|
| index(...)
| S.index(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| isalnum(self, /)
| Return True if the string is an alpha-numeric string, False otherwise.
|
| A string is alpha-numeric if all characters in the string are alpha-numeric and
| there is at least one character in the string.
|
| isalpha(self, /)
| Return True if the string is an alphabetic string, False otherwise.
|
| A string is alphabetic if all characters in the string are alphabetic and there
| is at least one character in the string.
|
| isascii(self, /)
| Return True if all characters in the string are ASCII, False otherwise.
|
| ASCII characters have code points in the range U+0000-U+007F.
| Empty string is ASCII too.
|
| isdecimal(self, /)
| Return True if the string is a decimal string, False otherwise.
|
| A string is a decimal string if all characters in the string are decimal and
| there is at least one character in the string.
|
| isdigit(self, /)
| Return True if the string is a digit string, False otherwise.
|
| A string is a digit string if all characters in the string are digits and there
| is at least one character in the string.
|
| isidentifier(self, /)
| Return True if the string is a valid Python identifier, False otherwise.
|
| Call keyword.iskeyword(s) to test whether string s is a reserved identifier,
| such as "def" or "class".
|
| islower(self, /)
| Return True if the string is a lowercase string, False otherwise.
|
| A string is lowercase if all cased characters in the string are lowercase and
| there is at least one cased character in the string.
|
| isnumeric(self, /)
| Return True if the string is a numeric string, False otherwise.
|
| A string is numeric if all characters in the string are numeric and there is at
| least one character in the string.
|
| isprintable(self, /)
| Return True if the string is printable, False otherwise.
|
| A string is printable if all of its characters are considered printable in
| repr() or if it is empty.
|
| isspace(self, /)
| Return True if the string is a whitespace string, False otherwise.
|
| A string is whitespace if all characters in the string are whitespace and there
| is at least one character in the string.
|
| istitle(self, /)
| Return True if the string is a title-cased string, False otherwise.
|
| In a title-cased string, upper- and title-case characters may only
| follow uncased characters and lowercase characters only cased ones.
|
| isupper(self, /)
| Return True if the string is an uppercase string, False otherwise.
|
| A string is uppercase if all cased characters in the string are uppercase and
| there is at least one cased character in the string.
|
| join(self, iterable, /)
| Concatenate any number of strings.
|
| The string whose method is called is inserted in between each given string.
| The result is returned as a new string.
|
| Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
|
| ljust(self, width, fillchar=' ', /)
| Return a left-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| lower(self, /)
| Return a copy of the string converted to lowercase.
|
| lstrip(self, chars=None, /)
| Return a copy of the string with leading whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| partition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string. If the separator is found,
| returns a 3-tuple containing the part before the separator, the separator
| itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing the original string
| and two empty strings.
|
| removeprefix(self, prefix, /)
| Return a str with the given prefix string removed if present.
|
| If the string starts with the prefix string, return string[len(prefix):].
| Otherwise, return a copy of the original string.
|
| removesuffix(self, suffix, /)
| Return a str with the given suffix string removed if present.
|
| If the string ends with the suffix string and that suffix is not empty,
| return string[:-len(suffix)]. Otherwise, return a copy of the original
| string.
|
| replace(self, old, new, count=-1, /)
| Return a copy with all occurrences of substring old replaced by new.
|
| count
| Maximum number of occurrences to replace.
| -1 (the default value) means replace all occurrences.
|
| If the optional argument count is given, only the first count occurrences are
| replaced.
|
| rfind(...)
| S.rfind(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| rindex(...)
| S.rindex(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| rjust(self, width, fillchar=' ', /)
| Return a right-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| rpartition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string, starting at the end. If
| the separator is found, returns a 3-tuple containing the part before the
| separator, the separator itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing two empty strings
| and the original string.
|
| rsplit(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the end of the string and works to the front.
|
| rstrip(self, chars=None, /)
| Return a copy of the string with trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| split(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the front of the string and works to the end.
|
| Note, str.split() is mainly useful for data that has been intentionally
| delimited. With natural text that includes punctuation, consider using
| the regular expression module.
|
| splitlines(self, /, keepends=False)
| Return a list of the lines in the string, breaking at line boundaries.
|
| Line breaks are not included in the resulting list unless keepends is given and
| true.
|
| startswith(...)
| S.startswith(prefix[, start[, end]]) -> bool
|
| Return True if S starts with the specified prefix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| prefix can also be a tuple of strings to try.
|
| strip(self, chars=None, /)
| Return a copy of the string with leading and trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| swapcase(self, /)
| Convert uppercase characters to lowercase and lowercase characters to uppercase.
|
| title(self, /)
| Return a version of the string where each word is titlecased.
|
| More specifically, words start with uppercased characters and all remaining
| cased characters have lower case.
|
| translate(self, table, /)
| Replace each character in the string using the given translation table.
|
| table
| Translation table, which must be a mapping of Unicode ordinals to
| Unicode ordinals, strings, or None.
|
| The table must implement lookup/indexing via __getitem__, for instance a
| dictionary or list. If this operation raises LookupError, the character is
| left untouched. Characters mapped to None are deleted.
|
| upper(self, /)
| Return a copy of the string converted to uppercase.
|
| zfill(self, width, /)
| Pad a numeric string with zeros on the left, to fill a field of the given width.
|
| The string is never truncated.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.str:
|
| maketrans(...)
| Return a translation table usable for str.translate().
|
| If there is only one argument, it must be a dictionary mapping Unicode
| ordinals (integers) or characters to Unicode ordinals, strings or None.
| Character keys will be then converted to ordinals.
| If there are two arguments, they must be strings of equal length, and
| in the resulting dictionary, each character in x will be mapped to the
| character at the same position in y. If there is a third argument, it
| must be a string, whose characters will be mapped to None in the result.
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class GatewaySecretInfo(mlflow.entities._mlflow_object._MlflowObject)
| GatewaySecretInfo(secret_id: str, secret_name: str, masked_values: dict[str, str], created_at: int, last_updated_at: int, provider: str | None = None, auth_config: dict[str, typing.Any] | None = None, workspace: str | None = None, created_by: str | None = None, last_updated_by: str | None = None) -> None
|
| Metadata about an encrypted secret for authenticating with LLM providers.
|
| This entity contains metadata, masked value, and auth configuration of a secret,
| but NOT the decrypted secret value itself. The actual secret is stored encrypted
| using envelope encryption (DEK encrypted by KEK).
|
| NB: secret_id and secret_name are IMMUTABLE after creation. They are used as AAD
| (Additional Authenticated Data) during AES-GCM encryption. If either is modified
| in the database, decryption will fail. To "rename" a secret, create a new one with
| the desired name and delete the old one. See mlflow/utils/crypto.py:_create_aad().
|
| This dataclass is frozen (immutable) because:
| 1. It represents a read-only view of database state
| 2. secret_id and secret_name must never be modified (used in encryption AAD)
| 3. Database triggers also enforce immutability of these fields
|
| Args:
| secret_id: Unique identifier for this secret. IMMUTABLE - used in AAD for encryption.
| secret_name: User-friendly name for the secret. IMMUTABLE - used in AAD for encryption.
| masked_values: Masked version of the secret values for display as key-value pairs.
| For simple API keys: ``{"api_key": "sk-...xyz123"}``.
| For compound credentials: ``{"aws_access_key_id": "AKI...1234", ...}``.
| created_at: Timestamp (milliseconds) when the secret was created.
| last_updated_at: Timestamp (milliseconds) when the secret was last updated.
| provider: LLM provider this secret is for (e.g., "openai", "anthropic").
| auth_config: Provider-specific configuration (e.g., region, project_id).
| This is non-sensitive metadata useful for UI disambiguation.
| workspace: Workspace that owns the secret.
| created_by: User ID who created the secret.
| last_updated_by: User ID who last updated the secret.
|
| Method resolution order:
| GatewaySecretInfo
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __delattr__(self, name)
| Implement delattr(self, name).
|
| __eq__(self, other)
| Return self==value.
|
| __hash__(self)
| Return hash(self).
|
| __init__(self, secret_id: str, secret_name: str, masked_values: dict[str, str], created_at: int, last_updated_at: int, provider: str | None = None, auth_config: dict[str, typing.Any] | None = None, workspace: str | None = None, created_by: str | None = None, last_updated_by: str | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __post_init__(self)
|
| __repr__(self)
| Return repr(self).
|
| __setattr__(self, name, value)
| Implement setattr(self, name, value).
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'auth_config': dict[str, typing.Any] | None, 'creat...
|
| __dataclass_fields__ = {'auth_config': Field(name='auth_config',type=d...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __match_args__ = ('secret_id', 'secret_name', 'masked_values', 'create...
|
| auth_config = None
|
| created_by = None
|
| last_updated_by = None
|
| provider = None
|
| workspace = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class GuardrailAction(builtins.str, enum.Enum)
| GuardrailAction(*values)
|
| Method resolution order:
| GuardrailAction
| builtins.str
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec) from enum.Enum
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__(self) -> 'str'
| Return str(self).
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| SANITIZATION = <GuardrailAction.SANITIZATION: 'SANITIZATION'>
|
| VALIDATION = <GuardrailAction.VALIDATION: 'VALIDATION'>
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.str:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(...)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __sizeof__(self, /)
| Return the size of the string in memory, in bytes.
|
| capitalize(self, /)
| Return a capitalized version of the string.
|
| More specifically, make the first character have upper case and the rest lower
| case.
|
| casefold(self, /)
| Return a version of the string suitable for caseless comparisons.
|
| center(self, width, fillchar=' ', /)
| Return a centered string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| count(...)
| S.count(sub[, start[, end]]) -> int
|
| Return the number of non-overlapping occurrences of substring sub in
| string S[start:end]. Optional arguments start and end are
| interpreted as in slice notation.
|
| encode(self, /, encoding='utf-8', errors='strict')
| Encode the string using the codec registered for encoding.
|
| encoding
| The encoding in which to encode the string.
| errors
| The error handling scheme to use for encoding errors.
| The default is 'strict' meaning that encoding errors raise a
| UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
| 'xmlcharrefreplace' as well as any other name registered with
| codecs.register_error that can handle UnicodeEncodeErrors.
|
| endswith(...)
| S.endswith(suffix[, start[, end]]) -> bool
|
| Return True if S ends with the specified suffix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| suffix can also be a tuple of strings to try.
|
| expandtabs(self, /, tabsize=8)
| Return a copy where all tab characters are expanded using spaces.
|
| If tabsize is not given, a tab size of 8 characters is assumed.
|
| find(...)
| S.find(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| format(...)
| S.format(*args, **kwargs) -> str
|
| Return a formatted version of S, using substitutions from args and kwargs.
| The substitutions are identified by braces ('{' and '}').
|
| format_map(...)
| S.format_map(mapping) -> str
|
| Return a formatted version of S, using substitutions from mapping.
| The substitutions are identified by braces ('{' and '}').
|
| index(...)
| S.index(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| isalnum(self, /)
| Return True if the string is an alpha-numeric string, False otherwise.
|
| A string is alpha-numeric if all characters in the string are alpha-numeric and
| there is at least one character in the string.
|
| isalpha(self, /)
| Return True if the string is an alphabetic string, False otherwise.
|
| A string is alphabetic if all characters in the string are alphabetic and there
| is at least one character in the string.
|
| isascii(self, /)
| Return True if all characters in the string are ASCII, False otherwise.
|
| ASCII characters have code points in the range U+0000-U+007F.
| Empty string is ASCII too.
|
| isdecimal(self, /)
| Return True if the string is a decimal string, False otherwise.
|
| A string is a decimal string if all characters in the string are decimal and
| there is at least one character in the string.
|
| isdigit(self, /)
| Return True if the string is a digit string, False otherwise.
|
| A string is a digit string if all characters in the string are digits and there
| is at least one character in the string.
|
| isidentifier(self, /)
| Return True if the string is a valid Python identifier, False otherwise.
|
| Call keyword.iskeyword(s) to test whether string s is a reserved identifier,
| such as "def" or "class".
|
| islower(self, /)
| Return True if the string is a lowercase string, False otherwise.
|
| A string is lowercase if all cased characters in the string are lowercase and
| there is at least one cased character in the string.
|
| isnumeric(self, /)
| Return True if the string is a numeric string, False otherwise.
|
| A string is numeric if all characters in the string are numeric and there is at
| least one character in the string.
|
| isprintable(self, /)
| Return True if the string is printable, False otherwise.
|
| A string is printable if all of its characters are considered printable in
| repr() or if it is empty.
|
| isspace(self, /)
| Return True if the string is a whitespace string, False otherwise.
|
| A string is whitespace if all characters in the string are whitespace and there
| is at least one character in the string.
|
| istitle(self, /)
| Return True if the string is a title-cased string, False otherwise.
|
| In a title-cased string, upper- and title-case characters may only
| follow uncased characters and lowercase characters only cased ones.
|
| isupper(self, /)
| Return True if the string is an uppercase string, False otherwise.
|
| A string is uppercase if all cased characters in the string are uppercase and
| there is at least one cased character in the string.
|
| join(self, iterable, /)
| Concatenate any number of strings.
|
| The string whose method is called is inserted in between each given string.
| The result is returned as a new string.
|
| Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
|
| ljust(self, width, fillchar=' ', /)
| Return a left-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| lower(self, /)
| Return a copy of the string converted to lowercase.
|
| lstrip(self, chars=None, /)
| Return a copy of the string with leading whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| partition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string. If the separator is found,
| returns a 3-tuple containing the part before the separator, the separator
| itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing the original string
| and two empty strings.
|
| removeprefix(self, prefix, /)
| Return a str with the given prefix string removed if present.
|
| If the string starts with the prefix string, return string[len(prefix):].
| Otherwise, return a copy of the original string.
|
| removesuffix(self, suffix, /)
| Return a str with the given suffix string removed if present.
|
| If the string ends with the suffix string and that suffix is not empty,
| return string[:-len(suffix)]. Otherwise, return a copy of the original
| string.
|
| replace(self, old, new, count=-1, /)
| Return a copy with all occurrences of substring old replaced by new.
|
| count
| Maximum number of occurrences to replace.
| -1 (the default value) means replace all occurrences.
|
| If the optional argument count is given, only the first count occurrences are
| replaced.
|
| rfind(...)
| S.rfind(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| rindex(...)
| S.rindex(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| rjust(self, width, fillchar=' ', /)
| Return a right-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| rpartition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string, starting at the end. If
| the separator is found, returns a 3-tuple containing the part before the
| separator, the separator itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing two empty strings
| and the original string.
|
| rsplit(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the end of the string and works to the front.
|
| rstrip(self, chars=None, /)
| Return a copy of the string with trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| split(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the front of the string and works to the end.
|
| Note, str.split() is mainly useful for data that has been intentionally
| delimited. With natural text that includes punctuation, consider using
| the regular expression module.
|
| splitlines(self, /, keepends=False)
| Return a list of the lines in the string, breaking at line boundaries.
|
| Line breaks are not included in the resulting list unless keepends is given and
| true.
|
| startswith(...)
| S.startswith(prefix[, start[, end]]) -> bool
|
| Return True if S starts with the specified prefix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| prefix can also be a tuple of strings to try.
|
| strip(self, chars=None, /)
| Return a copy of the string with leading and trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| swapcase(self, /)
| Convert uppercase characters to lowercase and lowercase characters to uppercase.
|
| title(self, /)
| Return a version of the string where each word is titlecased.
|
| More specifically, words start with uppercased characters and all remaining
| cased characters have lower case.
|
| translate(self, table, /)
| Replace each character in the string using the given translation table.
|
| table
| Translation table, which must be a mapping of Unicode ordinals to
| Unicode ordinals, strings, or None.
|
| The table must implement lookup/indexing via __getitem__, for instance a
| dictionary or list. If this operation raises LookupError, the character is
| left untouched. Characters mapped to None are deleted.
|
| upper(self, /)
| Return a copy of the string converted to uppercase.
|
| zfill(self, width, /)
| Pad a numeric string with zeros on the left, to fill a field of the given width.
|
| The string is never truncated.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.str:
|
| maketrans(...)
| Return a translation table usable for str.translate().
|
| If there is only one argument, it must be a dictionary mapping Unicode
| ordinals (integers) or characters to Unicode ordinals, strings or None.
| Character keys will be then converted to ordinals.
| If there are two arguments, they must be strings of equal length, and
| in the resulting dictionary, each character in x will be mapped to the
| character at the same position in y. If there is a third argument, it
| must be a string, whose characters will be mapped to None in the result.
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class GuardrailStage(builtins.str, enum.Enum)
| GuardrailStage(*values)
|
| Method resolution order:
| GuardrailStage
| builtins.str
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec) from enum.Enum
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__(self) -> 'str'
| Return str(self).
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| AFTER = <GuardrailStage.AFTER: 'AFTER'>
|
| BEFORE = <GuardrailStage.BEFORE: 'BEFORE'>
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.str:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(...)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __sizeof__(self, /)
| Return the size of the string in memory, in bytes.
|
| capitalize(self, /)
| Return a capitalized version of the string.
|
| More specifically, make the first character have upper case and the rest lower
| case.
|
| casefold(self, /)
| Return a version of the string suitable for caseless comparisons.
|
| center(self, width, fillchar=' ', /)
| Return a centered string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| count(...)
| S.count(sub[, start[, end]]) -> int
|
| Return the number of non-overlapping occurrences of substring sub in
| string S[start:end]. Optional arguments start and end are
| interpreted as in slice notation.
|
| encode(self, /, encoding='utf-8', errors='strict')
| Encode the string using the codec registered for encoding.
|
| encoding
| The encoding in which to encode the string.
| errors
| The error handling scheme to use for encoding errors.
| The default is 'strict' meaning that encoding errors raise a
| UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
| 'xmlcharrefreplace' as well as any other name registered with
| codecs.register_error that can handle UnicodeEncodeErrors.
|
| endswith(...)
| S.endswith(suffix[, start[, end]]) -> bool
|
| Return True if S ends with the specified suffix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| suffix can also be a tuple of strings to try.
|
| expandtabs(self, /, tabsize=8)
| Return a copy where all tab characters are expanded using spaces.
|
| If tabsize is not given, a tab size of 8 characters is assumed.
|
| find(...)
| S.find(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| format(...)
| S.format(*args, **kwargs) -> str
|
| Return a formatted version of S, using substitutions from args and kwargs.
| The substitutions are identified by braces ('{' and '}').
|
| format_map(...)
| S.format_map(mapping) -> str
|
| Return a formatted version of S, using substitutions from mapping.
| The substitutions are identified by braces ('{' and '}').
|
| index(...)
| S.index(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| isalnum(self, /)
| Return True if the string is an alpha-numeric string, False otherwise.
|
| A string is alpha-numeric if all characters in the string are alpha-numeric and
| there is at least one character in the string.
|
| isalpha(self, /)
| Return True if the string is an alphabetic string, False otherwise.
|
| A string is alphabetic if all characters in the string are alphabetic and there
| is at least one character in the string.
|
| isascii(self, /)
| Return True if all characters in the string are ASCII, False otherwise.
|
| ASCII characters have code points in the range U+0000-U+007F.
| Empty string is ASCII too.
|
| isdecimal(self, /)
| Return True if the string is a decimal string, False otherwise.
|
| A string is a decimal string if all characters in the string are decimal and
| there is at least one character in the string.
|
| isdigit(self, /)
| Return True if the string is a digit string, False otherwise.
|
| A string is a digit string if all characters in the string are digits and there
| is at least one character in the string.
|
| isidentifier(self, /)
| Return True if the string is a valid Python identifier, False otherwise.
|
| Call keyword.iskeyword(s) to test whether string s is a reserved identifier,
| such as "def" or "class".
|
| islower(self, /)
| Return True if the string is a lowercase string, False otherwise.
|
| A string is lowercase if all cased characters in the string are lowercase and
| there is at least one cased character in the string.
|
| isnumeric(self, /)
| Return True if the string is a numeric string, False otherwise.
|
| A string is numeric if all characters in the string are numeric and there is at
| least one character in the string.
|
| isprintable(self, /)
| Return True if the string is printable, False otherwise.
|
| A string is printable if all of its characters are considered printable in
| repr() or if it is empty.
|
| isspace(self, /)
| Return True if the string is a whitespace string, False otherwise.
|
| A string is whitespace if all characters in the string are whitespace and there
| is at least one character in the string.
|
| istitle(self, /)
| Return True if the string is a title-cased string, False otherwise.
|
| In a title-cased string, upper- and title-case characters may only
| follow uncased characters and lowercase characters only cased ones.
|
| isupper(self, /)
| Return True if the string is an uppercase string, False otherwise.
|
| A string is uppercase if all cased characters in the string are uppercase and
| there is at least one cased character in the string.
|
| join(self, iterable, /)
| Concatenate any number of strings.
|
| The string whose method is called is inserted in between each given string.
| The result is returned as a new string.
|
| Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
|
| ljust(self, width, fillchar=' ', /)
| Return a left-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| lower(self, /)
| Return a copy of the string converted to lowercase.
|
| lstrip(self, chars=None, /)
| Return a copy of the string with leading whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| partition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string. If the separator is found,
| returns a 3-tuple containing the part before the separator, the separator
| itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing the original string
| and two empty strings.
|
| removeprefix(self, prefix, /)
| Return a str with the given prefix string removed if present.
|
| If the string starts with the prefix string, return string[len(prefix):].
| Otherwise, return a copy of the original string.
|
| removesuffix(self, suffix, /)
| Return a str with the given suffix string removed if present.
|
| If the string ends with the suffix string and that suffix is not empty,
| return string[:-len(suffix)]. Otherwise, return a copy of the original
| string.
|
| replace(self, old, new, count=-1, /)
| Return a copy with all occurrences of substring old replaced by new.
|
| count
| Maximum number of occurrences to replace.
| -1 (the default value) means replace all occurrences.
|
| If the optional argument count is given, only the first count occurrences are
| replaced.
|
| rfind(...)
| S.rfind(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| rindex(...)
| S.rindex(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| rjust(self, width, fillchar=' ', /)
| Return a right-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| rpartition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string, starting at the end. If
| the separator is found, returns a 3-tuple containing the part before the
| separator, the separator itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing two empty strings
| and the original string.
|
| rsplit(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the end of the string and works to the front.
|
| rstrip(self, chars=None, /)
| Return a copy of the string with trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| split(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the front of the string and works to the end.
|
| Note, str.split() is mainly useful for data that has been intentionally
| delimited. With natural text that includes punctuation, consider using
| the regular expression module.
|
| splitlines(self, /, keepends=False)
| Return a list of the lines in the string, breaking at line boundaries.
|
| Line breaks are not included in the resulting list unless keepends is given and
| true.
|
| startswith(...)
| S.startswith(prefix[, start[, end]]) -> bool
|
| Return True if S starts with the specified prefix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| prefix can also be a tuple of strings to try.
|
| strip(self, chars=None, /)
| Return a copy of the string with leading and trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| swapcase(self, /)
| Convert uppercase characters to lowercase and lowercase characters to uppercase.
|
| title(self, /)
| Return a version of the string where each word is titlecased.
|
| More specifically, words start with uppercased characters and all remaining
| cased characters have lower case.
|
| translate(self, table, /)
| Replace each character in the string using the given translation table.
|
| table
| Translation table, which must be a mapping of Unicode ordinals to
| Unicode ordinals, strings, or None.
|
| The table must implement lookup/indexing via __getitem__, for instance a
| dictionary or list. If this operation raises LookupError, the character is
| left untouched. Characters mapped to None are deleted.
|
| upper(self, /)
| Return a copy of the string converted to uppercase.
|
| zfill(self, width, /)
| Pad a numeric string with zeros on the left, to fill a field of the given width.
|
| The string is never truncated.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.str:
|
| maketrans(...)
| Return a translation table usable for str.translate().
|
| If there is only one argument, it must be a dictionary mapping Unicode
| ordinals (integers) or characters to Unicode ordinals, strings or None.
| Character keys will be then converted to ordinals.
| If there are two arguments, they must be strings of equal length, and
| in the resulting dictionary, each character in x will be mapped to the
| character at the same position in y. If there is a third argument, it
| must be a string, whose characters will be mapped to None in the result.
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class InferenceTableLocation(TraceLocationBase)
| InferenceTableLocation(full_table_name: str) -> None
|
| .. Warning:: ``mlflow.entities.trace_location.InferenceTableLocation`` is deprecated since 3.7.0. This method will be removed in a future release.
|
| Represents the location of a Databricks inference table.
|
| Args:
| full_table_name: The fully qualified name of the inference table where
| the trace is stored, in the format of `<catalog>.<schema>.<table>`.
|
| Method resolution order:
| InferenceTableLocation
| TraceLocationBase
| mlflow.entities._mlflow_object._MlflowObject
| abc.ABC
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, full_table_name: str) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| to_dict(self) -> dict[str, typing.Any]
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dict(d: dict[str, typing.Any]) -> 'InferenceTableLocation'
|
| from_proto(proto) -> 'InferenceTableLocation'
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset()
|
| __annotations__ = {'full_table_name': <class 'str'>}
|
| __dataclass_fields__ = {'full_table_name': Field(name='full_table_name...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('full_table_name',)
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class InputTag(mlflow.entities._mlflow_object._MlflowObject)
| InputTag(key: str, value: str) -> None
|
| Input tag object associated with a dataset.
|
| Method resolution order:
| InputTag
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other: mlflow.entities._mlflow_object._MlflowObject) -> bool
| Return self==value.
|
| __init__(self, key: str, value: str) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| key
| String name of the input tag.
|
| value
| String value of the input tag.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class Issue(mlflow.entities._mlflow_object._MlflowObject)
| Issue(issue_id: 'str', experiment_id: 'str', name: 'str', description: 'str', status: 'IssueStatus', created_timestamp: 'int', last_updated_timestamp: 'int', severity: 'IssueSeverity | None' = None, root_causes: 'list[str] | None' = None, source_run_id: 'str | None' = None, categories: 'list[str] | None' = None, created_by: 'str | None' = None, trace_count: 'int | None' = None) -> None
|
| An Issue represents a quality or operational problem discovered in traces.
|
| Method resolution order:
| Issue
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, issue_id: 'str', experiment_id: 'str', name: 'str', description: 'str', status: 'IssueStatus', created_timestamp: 'int', last_updated_timestamp: 'int', severity: 'IssueSeverity | None' = None, root_causes: 'list[str] | None' = None, source_run_id: 'str | None' = None, categories: 'list[str] | None' = None, created_by: 'str | None' = None, trace_count: 'int | None' = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| to_dictionary(self) -> 'dict[str, Any]'
| Convert Issue to dictionary representation.
|
| to_proto(self) -> 'ProtoIssue'
| Convert Issue to protobuf representation.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dictionary(issue_dict: 'dict[str, Any]') -> 'Issue'
| Create Issue from dictionary representation.
|
| from_proto(proto: 'ProtoIssue') -> 'Issue'
| Create Issue from protobuf representation.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'categories': 'list[str] | None', 'created_by': 'st...
|
| __dataclass_fields__ = {'categories': Field(name='categories',type='li...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('issue_id', 'experiment_id', 'name', 'description', ...
|
| categories = None
|
| created_by = None
|
| root_causes = None
|
| severity = None
|
| source_run_id = None
|
| trace_count = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class IssueReference(Assessment)
| IssueReference(issue_id: 'str', issue_name: 'str', source: 'AssessmentSource | None' = None, trace_id: 'str | None' = None, run_id: 'str | None' = None, rationale: 'str | None' = None, metadata: 'dict[str, str] | None' = None, span_id: 'str | None' = None, create_time_ms: 'int | None' = None, last_update_time_ms: 'int | None' = None)
|
| Represents a reference to an issue associated with a trace. This type of assessment
| is used internally to link traces to discovered issues.
|
| Args:
| issue_id: The ID of the issue this assessment references (stored in assessment name).
| issue_name: The name of the issue (stored in the issue value).
| source: The source of the assessment. If not provided, the default source is CODE.
| trace_id: The ID of the trace associated with the assessment.
| run_id: The ID of the run that discovered the issue.
| rationale: The rationale / justification for the issue reference.
| span_id: The ID of the span associated with the assessment, if applicable.
| create_time_ms: The creation time of the assessment in milliseconds.
| last_update_time_ms: The last update time of the assessment in milliseconds.
|
| Method resolution order:
| IssueReference
| Assessment
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, issue_id: 'str', issue_name: 'str', source: 'AssessmentSource | None' = None, trace_id: 'str | None' = None, run_id: 'str | None' = None, rationale: 'str | None' = None, metadata: 'dict[str, str] | None' = None, span_id: 'str | None' = None, create_time_ms: 'int | None' = None, last_update_time_ms: 'int | None' = None)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dictionary(d: 'dict[str, Any]') -> "'IssueReference'"
|
| from_proto(proto) -> "'IssueReference'"
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| issue_id
|
| issue_name
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __dataclass_fields__ = {'assessment_id': Field(name='assessment_id',ty...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('name', 'source', 'trace_id', 'run_id', 'rationale',...
|
| ----------------------------------------------------------------------
| Methods inherited from Assessment:
|
| __post_init__(self)
|
| to_dictionary(self)
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Assessment:
|
| assessment_id = None
|
| create_time_ms = None
|
| error = None
|
| expectation = None
|
| feedback = None
|
| issue = None
|
| last_update_time_ms = None
|
| metadata = None
|
| overrides = None
|
| rationale = None
|
| run_id = None
|
| span_id = None
|
| trace_id = None
|
| valid = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class IssueSeverity(builtins.str, enum.Enum)
| IssueSeverity(*values)
|
| Enum for severity level of an :py:class:`mlflow.entities.Issue`.
|
| Method resolution order:
| IssueSeverity
| builtins.str
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec) from enum.Enum
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(self, other) -> 'bool'
| Return self>=value.
|
| __gt__(self, other) -> 'bool'
| Return self>value.
|
| __le__(self, other) -> 'bool'
| Return self<=value.
|
| __lt__(self, other) -> 'bool'
| Return self<value.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__(self)
| Return str(self).
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| HIGH = <IssueSeverity.HIGH: 'high'>
|
| LOW = <IssueSeverity.LOW: 'low'>
|
| MEDIUM = <IssueSeverity.MEDIUM: 'medium'>
|
| NOT_AN_ISSUE = <IssueSeverity.NOT_AN_ISSUE: 'not_an_issue'>
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.str:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(...)
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __len__(self, /)
| Return len(self).
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __sizeof__(self, /)
| Return the size of the string in memory, in bytes.
|
| capitalize(self, /)
| Return a capitalized version of the string.
|
| More specifically, make the first character have upper case and the rest lower
| case.
|
| casefold(self, /)
| Return a version of the string suitable for caseless comparisons.
|
| center(self, width, fillchar=' ', /)
| Return a centered string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| count(...)
| S.count(sub[, start[, end]]) -> int
|
| Return the number of non-overlapping occurrences of substring sub in
| string S[start:end]. Optional arguments start and end are
| interpreted as in slice notation.
|
| encode(self, /, encoding='utf-8', errors='strict')
| Encode the string using the codec registered for encoding.
|
| encoding
| The encoding in which to encode the string.
| errors
| The error handling scheme to use for encoding errors.
| The default is 'strict' meaning that encoding errors raise a
| UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
| 'xmlcharrefreplace' as well as any other name registered with
| codecs.register_error that can handle UnicodeEncodeErrors.
|
| endswith(...)
| S.endswith(suffix[, start[, end]]) -> bool
|
| Return True if S ends with the specified suffix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| suffix can also be a tuple of strings to try.
|
| expandtabs(self, /, tabsize=8)
| Return a copy where all tab characters are expanded using spaces.
|
| If tabsize is not given, a tab size of 8 characters is assumed.
|
| find(...)
| S.find(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| format(...)
| S.format(*args, **kwargs) -> str
|
| Return a formatted version of S, using substitutions from args and kwargs.
| The substitutions are identified by braces ('{' and '}').
|
| format_map(...)
| S.format_map(mapping) -> str
|
| Return a formatted version of S, using substitutions from mapping.
| The substitutions are identified by braces ('{' and '}').
|
| index(...)
| S.index(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| isalnum(self, /)
| Return True if the string is an alpha-numeric string, False otherwise.
|
| A string is alpha-numeric if all characters in the string are alpha-numeric and
| there is at least one character in the string.
|
| isalpha(self, /)
| Return True if the string is an alphabetic string, False otherwise.
|
| A string is alphabetic if all characters in the string are alphabetic and there
| is at least one character in the string.
|
| isascii(self, /)
| Return True if all characters in the string are ASCII, False otherwise.
|
| ASCII characters have code points in the range U+0000-U+007F.
| Empty string is ASCII too.
|
| isdecimal(self, /)
| Return True if the string is a decimal string, False otherwise.
|
| A string is a decimal string if all characters in the string are decimal and
| there is at least one character in the string.
|
| isdigit(self, /)
| Return True if the string is a digit string, False otherwise.
|
| A string is a digit string if all characters in the string are digits and there
| is at least one character in the string.
|
| isidentifier(self, /)
| Return True if the string is a valid Python identifier, False otherwise.
|
| Call keyword.iskeyword(s) to test whether string s is a reserved identifier,
| such as "def" or "class".
|
| islower(self, /)
| Return True if the string is a lowercase string, False otherwise.
|
| A string is lowercase if all cased characters in the string are lowercase and
| there is at least one cased character in the string.
|
| isnumeric(self, /)
| Return True if the string is a numeric string, False otherwise.
|
| A string is numeric if all characters in the string are numeric and there is at
| least one character in the string.
|
| isprintable(self, /)
| Return True if the string is printable, False otherwise.
|
| A string is printable if all of its characters are considered printable in
| repr() or if it is empty.
|
| isspace(self, /)
| Return True if the string is a whitespace string, False otherwise.
|
| A string is whitespace if all characters in the string are whitespace and there
| is at least one character in the string.
|
| istitle(self, /)
| Return True if the string is a title-cased string, False otherwise.
|
| In a title-cased string, upper- and title-case characters may only
| follow uncased characters and lowercase characters only cased ones.
|
| isupper(self, /)
| Return True if the string is an uppercase string, False otherwise.
|
| A string is uppercase if all cased characters in the string are uppercase and
| there is at least one cased character in the string.
|
| join(self, iterable, /)
| Concatenate any number of strings.
|
| The string whose method is called is inserted in between each given string.
| The result is returned as a new string.
|
| Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
|
| ljust(self, width, fillchar=' ', /)
| Return a left-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| lower(self, /)
| Return a copy of the string converted to lowercase.
|
| lstrip(self, chars=None, /)
| Return a copy of the string with leading whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| partition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string. If the separator is found,
| returns a 3-tuple containing the part before the separator, the separator
| itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing the original string
| and two empty strings.
|
| removeprefix(self, prefix, /)
| Return a str with the given prefix string removed if present.
|
| If the string starts with the prefix string, return string[len(prefix):].
| Otherwise, return a copy of the original string.
|
| removesuffix(self, suffix, /)
| Return a str with the given suffix string removed if present.
|
| If the string ends with the suffix string and that suffix is not empty,
| return string[:-len(suffix)]. Otherwise, return a copy of the original
| string.
|
| replace(self, old, new, count=-1, /)
| Return a copy with all occurrences of substring old replaced by new.
|
| count
| Maximum number of occurrences to replace.
| -1 (the default value) means replace all occurrences.
|
| If the optional argument count is given, only the first count occurrences are
| replaced.
|
| rfind(...)
| S.rfind(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| rindex(...)
| S.rindex(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| rjust(self, width, fillchar=' ', /)
| Return a right-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| rpartition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string, starting at the end. If
| the separator is found, returns a 3-tuple containing the part before the
| separator, the separator itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing two empty strings
| and the original string.
|
| rsplit(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the end of the string and works to the front.
|
| rstrip(self, chars=None, /)
| Return a copy of the string with trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| split(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the front of the string and works to the end.
|
| Note, str.split() is mainly useful for data that has been intentionally
| delimited. With natural text that includes punctuation, consider using
| the regular expression module.
|
| splitlines(self, /, keepends=False)
| Return a list of the lines in the string, breaking at line boundaries.
|
| Line breaks are not included in the resulting list unless keepends is given and
| true.
|
| startswith(...)
| S.startswith(prefix[, start[, end]]) -> bool
|
| Return True if S starts with the specified prefix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| prefix can also be a tuple of strings to try.
|
| strip(self, chars=None, /)
| Return a copy of the string with leading and trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| swapcase(self, /)
| Convert uppercase characters to lowercase and lowercase characters to uppercase.
|
| title(self, /)
| Return a version of the string where each word is titlecased.
|
| More specifically, words start with uppercased characters and all remaining
| cased characters have lower case.
|
| translate(self, table, /)
| Replace each character in the string using the given translation table.
|
| table
| Translation table, which must be a mapping of Unicode ordinals to
| Unicode ordinals, strings, or None.
|
| The table must implement lookup/indexing via __getitem__, for instance a
| dictionary or list. If this operation raises LookupError, the character is
| left untouched. Characters mapped to None are deleted.
|
| upper(self, /)
| Return a copy of the string converted to uppercase.
|
| zfill(self, width, /)
| Pad a numeric string with zeros on the left, to fill a field of the given width.
|
| The string is never truncated.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.str:
|
| maketrans(...)
| Return a translation table usable for str.translate().
|
| If there is only one argument, it must be a dictionary mapping Unicode
| ordinals (integers) or characters to Unicode ordinals, strings or None.
| Character keys will be then converted to ordinals.
| If there are two arguments, they must be strings of equal length, and
| in the resulting dictionary, each character in x will be mapped to the
| character at the same position in y. If there is a third argument, it
| must be a string, whose characters will be mapped to None in the result.
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class IssueStatus(builtins.str, enum.Enum)
| IssueStatus(*values)
|
| Enum for status of an :py:class:`mlflow.entities.Issue`.
|
| Method resolution order:
| IssueStatus
| builtins.str
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec) from enum.Enum
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__(self)
| Return str(self).
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| PENDING = <IssueStatus.PENDING: 'pending'>
|
| REJECTED = <IssueStatus.REJECTED: 'rejected'>
|
| RESOLVED = <IssueStatus.RESOLVED: 'resolved'>
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.str:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(...)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __sizeof__(self, /)
| Return the size of the string in memory, in bytes.
|
| capitalize(self, /)
| Return a capitalized version of the string.
|
| More specifically, make the first character have upper case and the rest lower
| case.
|
| casefold(self, /)
| Return a version of the string suitable for caseless comparisons.
|
| center(self, width, fillchar=' ', /)
| Return a centered string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| count(...)
| S.count(sub[, start[, end]]) -> int
|
| Return the number of non-overlapping occurrences of substring sub in
| string S[start:end]. Optional arguments start and end are
| interpreted as in slice notation.
|
| encode(self, /, encoding='utf-8', errors='strict')
| Encode the string using the codec registered for encoding.
|
| encoding
| The encoding in which to encode the string.
| errors
| The error handling scheme to use for encoding errors.
| The default is 'strict' meaning that encoding errors raise a
| UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
| 'xmlcharrefreplace' as well as any other name registered with
| codecs.register_error that can handle UnicodeEncodeErrors.
|
| endswith(...)
| S.endswith(suffix[, start[, end]]) -> bool
|
| Return True if S ends with the specified suffix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| suffix can also be a tuple of strings to try.
|
| expandtabs(self, /, tabsize=8)
| Return a copy where all tab characters are expanded using spaces.
|
| If tabsize is not given, a tab size of 8 characters is assumed.
|
| find(...)
| S.find(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| format(...)
| S.format(*args, **kwargs) -> str
|
| Return a formatted version of S, using substitutions from args and kwargs.
| The substitutions are identified by braces ('{' and '}').
|
| format_map(...)
| S.format_map(mapping) -> str
|
| Return a formatted version of S, using substitutions from mapping.
| The substitutions are identified by braces ('{' and '}').
|
| index(...)
| S.index(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| isalnum(self, /)
| Return True if the string is an alpha-numeric string, False otherwise.
|
| A string is alpha-numeric if all characters in the string are alpha-numeric and
| there is at least one character in the string.
|
| isalpha(self, /)
| Return True if the string is an alphabetic string, False otherwise.
|
| A string is alphabetic if all characters in the string are alphabetic and there
| is at least one character in the string.
|
| isascii(self, /)
| Return True if all characters in the string are ASCII, False otherwise.
|
| ASCII characters have code points in the range U+0000-U+007F.
| Empty string is ASCII too.
|
| isdecimal(self, /)
| Return True if the string is a decimal string, False otherwise.
|
| A string is a decimal string if all characters in the string are decimal and
| there is at least one character in the string.
|
| isdigit(self, /)
| Return True if the string is a digit string, False otherwise.
|
| A string is a digit string if all characters in the string are digits and there
| is at least one character in the string.
|
| isidentifier(self, /)
| Return True if the string is a valid Python identifier, False otherwise.
|
| Call keyword.iskeyword(s) to test whether string s is a reserved identifier,
| such as "def" or "class".
|
| islower(self, /)
| Return True if the string is a lowercase string, False otherwise.
|
| A string is lowercase if all cased characters in the string are lowercase and
| there is at least one cased character in the string.
|
| isnumeric(self, /)
| Return True if the string is a numeric string, False otherwise.
|
| A string is numeric if all characters in the string are numeric and there is at
| least one character in the string.
|
| isprintable(self, /)
| Return True if the string is printable, False otherwise.
|
| A string is printable if all of its characters are considered printable in
| repr() or if it is empty.
|
| isspace(self, /)
| Return True if the string is a whitespace string, False otherwise.
|
| A string is whitespace if all characters in the string are whitespace and there
| is at least one character in the string.
|
| istitle(self, /)
| Return True if the string is a title-cased string, False otherwise.
|
| In a title-cased string, upper- and title-case characters may only
| follow uncased characters and lowercase characters only cased ones.
|
| isupper(self, /)
| Return True if the string is an uppercase string, False otherwise.
|
| A string is uppercase if all cased characters in the string are uppercase and
| there is at least one cased character in the string.
|
| join(self, iterable, /)
| Concatenate any number of strings.
|
| The string whose method is called is inserted in between each given string.
| The result is returned as a new string.
|
| Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
|
| ljust(self, width, fillchar=' ', /)
| Return a left-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| lower(self, /)
| Return a copy of the string converted to lowercase.
|
| lstrip(self, chars=None, /)
| Return a copy of the string with leading whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| partition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string. If the separator is found,
| returns a 3-tuple containing the part before the separator, the separator
| itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing the original string
| and two empty strings.
|
| removeprefix(self, prefix, /)
| Return a str with the given prefix string removed if present.
|
| If the string starts with the prefix string, return string[len(prefix):].
| Otherwise, return a copy of the original string.
|
| removesuffix(self, suffix, /)
| Return a str with the given suffix string removed if present.
|
| If the string ends with the suffix string and that suffix is not empty,
| return string[:-len(suffix)]. Otherwise, return a copy of the original
| string.
|
| replace(self, old, new, count=-1, /)
| Return a copy with all occurrences of substring old replaced by new.
|
| count
| Maximum number of occurrences to replace.
| -1 (the default value) means replace all occurrences.
|
| If the optional argument count is given, only the first count occurrences are
| replaced.
|
| rfind(...)
| S.rfind(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| rindex(...)
| S.rindex(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| rjust(self, width, fillchar=' ', /)
| Return a right-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| rpartition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string, starting at the end. If
| the separator is found, returns a 3-tuple containing the part before the
| separator, the separator itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing two empty strings
| and the original string.
|
| rsplit(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the end of the string and works to the front.
|
| rstrip(self, chars=None, /)
| Return a copy of the string with trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| split(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the front of the string and works to the end.
|
| Note, str.split() is mainly useful for data that has been intentionally
| delimited. With natural text that includes punctuation, consider using
| the regular expression module.
|
| splitlines(self, /, keepends=False)
| Return a list of the lines in the string, breaking at line boundaries.
|
| Line breaks are not included in the resulting list unless keepends is given and
| true.
|
| startswith(...)
| S.startswith(prefix[, start[, end]]) -> bool
|
| Return True if S starts with the specified prefix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| prefix can also be a tuple of strings to try.
|
| strip(self, chars=None, /)
| Return a copy of the string with leading and trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| swapcase(self, /)
| Convert uppercase characters to lowercase and lowercase characters to uppercase.
|
| title(self, /)
| Return a version of the string where each word is titlecased.
|
| More specifically, words start with uppercased characters and all remaining
| cased characters have lower case.
|
| translate(self, table, /)
| Replace each character in the string using the given translation table.
|
| table
| Translation table, which must be a mapping of Unicode ordinals to
| Unicode ordinals, strings, or None.
|
| The table must implement lookup/indexing via __getitem__, for instance a
| dictionary or list. If this operation raises LookupError, the character is
| left untouched. Characters mapped to None are deleted.
|
| upper(self, /)
| Return a copy of the string converted to uppercase.
|
| zfill(self, width, /)
| Pad a numeric string with zeros on the left, to fill a field of the given width.
|
| The string is never truncated.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.str:
|
| maketrans(...)
| Return a translation table usable for str.translate().
|
| If there is only one argument, it must be a dictionary mapping Unicode
| ordinals (integers) or characters to Unicode ordinals, strings or None.
| Character keys will be then converted to ordinals.
| If there are two arguments, they must be strings of equal length, and
| in the resulting dictionary, each character in x will be mapped to the
| character at the same position in y. If there is a third argument, it
| must be a string, whose characters will be mapped to None in the result.
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class LifecycleStage(builtins.object)
| Class methods defined here:
|
| is_valid(lifecycle_stage)
|
| matches_view_type(view_type, lifecycle_stage)
|
| view_type_to_stages(view_type=3)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| ACTIVE = 'active'
|
| DELETED = 'deleted'
class Link(mlflow.entities._mlflow_object._MlflowObject)
| Link(trace_id: str, span_id: str, attributes: dict[str, typing.Any] | None = None) -> None
|
| Represents an OpenTelemetry Span Link that connects spans across traces.
|
| Span Links allow you to link spans that don't have a parent-child relationship,
| such as spans from different traces in multi-agent systems or distributed workflows.
|
| Args:
| trace_id: The trace ID of the linked span. Accepted formats include
| MLflow trace IDs (``tr-xxx``), v4 trace IDs (``trace:/<location>/<hex>``),
| and bare hex strings.
| span_id: The span ID within that trace (16-character hex string).
| attributes: Optional attributes describing the link relationship.
| Values must be JSON-serializable (``str``, ``int``, ``float``,
| ``bool``, or ``None``).
|
| Method resolution order:
| Link
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, trace_id: str, span_id: str, attributes: dict[str, typing.Any] | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| to_dict(self) -> dict[str, typing.Any]
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dict(data: dict[str, typing.Any]) -> 'Link'
|
| from_otel_proto(proto_link) -> 'Link'
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'attributes': dict[str, typing.Any] | None, 'span_i...
|
| __dataclass_fields__ = {'attributes': Field(name='attributes',type=dic...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('trace_id', 'span_id', 'attributes')
|
| attributes = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class LiveSpan(Span)
| LiveSpan(otel_span: opentelemetry.trace.span.Span, trace_id: str, span_type: str = 'UNKNOWN')
|
| A "live" version of the :py:class:`Span <mlflow.entities.Span>` class.
|
| The live spans are those being created and updated during the application runtime.
| When users start a new span using the tracing APIs within their code, this live span
| object is returned to get and set the span attributes, status, events, and etc.
|
| Method resolution order:
| LiveSpan
| Span
| builtins.object
|
| Methods defined here:
|
| __init__(self, otel_span: opentelemetry.trace.span.Span, trace_id: str, span_type: str = 'UNKNOWN')
| The `otel_span` argument takes an instance of OpenTelemetry Span class, which is
| indeed a subclass of ReadableSpan. Thanks to this, the getter methods of the Span
| class can be reused without any modification.
|
| Note that the constructor doesn't call the super().__init__ method, because the Span
| initialization logic is a bit different from the immutable span.
|
| add_event(self, event: mlflow.entities.span_event.SpanEvent)
| Add an event to the span.
|
| Args:
| event: The event to add to the span. This should be a
| :py:class:`SpanEvent <mlflow.entities.SpanEvent>` object.
|
| add_link(self, link: 'Link')
| Add a link to this span.
|
| Args:
| link: The link to add to the span. This should be a
| :py:class:`Link <mlflow.entities.Link>` object.
|
| end(self, outputs: typing.Any | None = None, attributes: dict[str, typing.Any] | None = None, status: mlflow.entities.span_status.SpanStatus | str | None = None, end_time_ns: int | None = None)
| End the span.
|
| outputs: Outputs to set on the span.
| attributes: A dictionary of attributes to set on the span. If the span already has
| attributes, the new attributes will be merged with the existing ones. If the same
| key already exists, the new value will overwrite the old one.
| status: The status of the span. This can be a
| :py:class:`SpanStatus <mlflow.entities.SpanStatus>` object or a string
| representing the status code defined in
| :py:class:`SpanStatusCode <mlflow.entities.SpanStatusCode>`
| e.g. ``"OK"``, ``"ERROR"``. The default status is OK.
| end_time_ns: The end time of the span in nano seconds since the UNIX epoch.
| If not provided, the current time will be used.
|
| :meta private:
|
| from_dict(cls, data: dict[str, typing.Any]) -> 'Span'
| Create a Span object from the given dictionary.
|
| record_exception(self, exception: str | Exception)
| Record an exception on the span, adding an exception event and setting span status to ERROR.
|
| Args:
| exception: The exception to record. Can be an Exception instance or a string
| describing the exception.
|
| set_attribute(self, key: str, value: Any)
| Set a single attribute to the span.
|
| set_attributes(self, attributes: dict[str, typing.Any])
| Set the attributes to the span. The attributes must be a dictionary of key-value pairs.
| This method is additive, i.e. it will add new attributes to the existing ones. If an
| attribute with the same key already exists, it will be overwritten.
|
| set_inputs(self, inputs: Any)
| Set the input values to the span.
|
| set_log_level(self, level: mlflow.entities.span_log_level.SpanLogLevel | str)
| Set the severity level of the span.
|
| Args:
| level: A :py:class:`SpanLogLevel <mlflow.entities.SpanLogLevel>` or
| its name (e.g. ``"INFO"``).
|
| set_outputs(self, outputs: Any)
| Set the output values to the span.
|
| set_span_type(self, span_type: str)
| Set the type of the span.
|
| set_status(self, status: mlflow.entities.span_status.SpanStatusCode | str)
| Set the status of the span.
|
| Args:
| status: The status of the span. This can be a
| :py:class:`SpanStatus <mlflow.entities.SpanStatus>` object or a string representing
| of the status code defined in
| :py:class:`SpanStatusCode <mlflow.entities.SpanStatusCode>`
| e.g. ``"OK"``, ``"ERROR"``.
|
| to_immutable_span(self) -> 'Span'
| Downcast the live span object to the immutable span.
|
| :meta private:
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_immutable_span(span: mlflow.entities.span.Span, parent_span_id: str | None = None, trace_id: str | None = None, experiment_id: str | None = None, otel_trace_id: str | None = None) -> 'LiveSpan'
| Create a new LiveSpan object from the given immutable span by
| cloning the underlying OpenTelemetry span within current context.
|
| This is particularly useful when we merging a remote trace into the current trace.
| We cannot merge the remote trace directly, because it is already stored as an immutable
| span, meaning that we cannot update metadata like trace ID, parent span ID,
| which are necessary for merging the trace.
|
| Args:
| span: The immutable span object to clone.
| parent_span_id: The parent span ID of the new span.
| If it is None, the span will be created as a root span.
| trace_id: The trace ID to be set on the new span. Specify this if you want to
| create the new span with a particular trace ID.
| experiment_id: The experiment ID to be set on the new span. If not specified, the
| experiment ID will be set to the current experiment ID.
| otel_trace_id: The OpenTelemetry trace ID of the new span in hex encoded format.
| If not specified, the newly generated trace ID will be used.
|
| Returns:
| The new LiveSpan object with the same state as the original span.
|
| :meta private:
|
| ----------------------------------------------------------------------
| Methods inherited from Span:
|
| __repr__(self)
| Return repr(self).
|
| get_attribute(self, key: str) -> typing.Any | None
| Get a single attribute value from the span.
|
| Args:
| key: The key of the attribute to get.
|
| Returns:
| The value of the attribute if it exists, otherwise None.
|
| to_dict(self) -> dict[str, typing.Any]
|
| to_otel_proto(self) -> opentelemetry.proto.trace.v1.trace_pb2.Span
| Convert to OpenTelemetry protobuf span format for OTLP export.
| This is an internal method used by the REST store for logging spans.
|
| Returns:
| An OpenTelemetry protobuf Span message.
|
| trace_id = <functools.cached_property object>
| The trace ID of the span, a unique identifier for the trace it belongs to.
|
| ----------------------------------------------------------------------
| Class methods inherited from Span:
|
| from_dict_v2(data: dict[str, typing.Any]) -> 'Span'
| Create a Span object from the given dictionary in v2 schema.
|
| from_otel_proto(otel_proto_span: opentelemetry.proto.trace.v1.trace_pb2.Span, location_id: str | None = None, *, preserve_request_id: bool = False, resource: opentelemetry.proto.resource.v1.resource_pb2.Resource | None = None) -> 'Span'
| Create a Span from an OpenTelemetry protobuf span.
|
| This is an internal method used for receiving spans via OTel protocol. By default,
| MLflow derives the canonical ``mlflow.traceRequestId`` from the OTLP trace ID so server
| ingest does not trust a client-sent request ID. Set ``preserve_request_id=True`` only for
| trusted internal round-trip flows, such as archived trace payload deserialization, where
| the stored MLflow request ID must be preserved exactly if present.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Span:
|
| attributes
| Get all attributes of the span.
|
| Returns:
| A dictionary of all attributes of the span.
|
| end_time_ns
| The end time of the span in nanosecond.
|
| events
| Get all events of the span.
|
| Returns:
| A list of all events of the span.
|
| inputs
| The input values of the span.
|
| links
| Get all links of the span.
|
| Returns:
| A list of all links of the span.
|
| llm_cost
| The cost information for the span in USD.
|
| Returns a dictionary with keys:
| - input_cost: Cost of input tokens
| - output_cost: Cost of output tokens
| - total_cost: Total cost (input + output)
|
| Returns None if cost information is not available.
|
| log_level
| The severity level of the span, or ``None`` if it was not classified.
|
| Set on a :py:class:`LiveSpan <mlflow.entities.LiveSpan>` via
| :py:meth:`set_log_level <mlflow.entities.LiveSpan.set_log_level>`,
| the ``log_level`` argument of :py:func:`mlflow.start_span`,
| :py:func:`mlflow.start_span_no_context`, or :py:func:`mlflow.trace`,
| or by an autologging integration on the user's behalf.
|
| model_name
| The model name used in the span.
|
| name
| The name of the span.
|
| outputs
| The output values of the span.
|
| parent_id
| The span ID of the parent span.
|
| request_id
| Deprecated. Use `trace_id` instead.
|
| span_id
| The ID of the span. This is only unique within a trace.
|
| span_type
| The type of the span.
|
| start_time_ns
| The start time of the span in nanosecond.
|
| status
| The status of the span.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Span:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class LoggedModel(mlflow.entities._mlflow_object._MlflowObject)
| LoggedModel(experiment_id: str, model_id: str, name: str, artifact_location: str, creation_timestamp: int, last_updated_timestamp: int, model_type: str | None = None, source_run_id: str | None = None, status: mlflow.entities.logged_model_status.LoggedModelStatus | int = <LoggedModelStatus.READY: 'READY'>, status_message: str | None = None, tags: list[mlflow.entities.logged_model_tag.LoggedModelTag] | dict[str, str] | None = None, params: list[mlflow.entities.logged_model_parameter.LoggedModelParameter] | dict[str, str] | None = None, metrics: list[mlflow.entities.metric.Metric] | None = None)
|
| MLflow entity representing a Model logged to an MLflow Experiment.
|
| Method resolution order:
| LoggedModel
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __init__(self, experiment_id: str, model_id: str, name: str, artifact_location: str, creation_timestamp: int, last_updated_timestamp: int, model_type: str | None = None, source_run_id: str | None = None, status: mlflow.entities.logged_model_status.LoggedModelStatus | int = <LoggedModelStatus.READY: 'READY'>, status_message: str | None = None, tags: list[mlflow.entities.logged_model_tag.LoggedModelTag] | dict[str, str] | None = None, params: list[mlflow.entities.logged_model_parameter.LoggedModelParameter] | dict[str, str] | None = None, metrics: list[mlflow.entities.metric.Metric] | None = None)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self) -> str
| Return repr(self).
|
| to_dictionary(self) -> dict[str, typing.Any]
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| creation_timestamp
| Integer. Model creation timestamp (milliseconds since the Unix epoch).
|
| model_uri
| URI of the model.
|
| params
| Model parameters.
|
| source_run_id
| String. MLflow run ID that generated this model.
|
| status_message
| String. Descriptive message for error status conditions.
|
| tags
| Dictionary of tag key (string) -> tag value for this Model.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| artifact_location
| String. Location of the model artifacts.
|
| experiment_id
| String. Experiment ID associated with this Model.
|
| last_updated_timestamp
| Integer. Timestamp of last update for this Model (milliseconds since the Unix
| epoch).
|
| metrics
| List of metrics associated with this Model.
|
| model_id
| String. Unique ID for this Model.
|
| model_type
| String. Type of the model.
|
| name
| String. Name for this Model.
|
| status
| String. Current status of this Model.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class LoggedModelInput(mlflow.entities._mlflow_object._MlflowObject)
| LoggedModelInput(model_id: str)
|
| ModelInput object associated with a Run.
|
| Method resolution order:
| LoggedModelInput
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other: mlflow.entities._mlflow_object._MlflowObject) -> bool
| Return self==value.
|
| __init__(self, model_id: str)
| Initialize self. See help(type(self)) for accurate signature.
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| model_id
| Model ID.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class LoggedModelOutput(mlflow.entities._mlflow_object._MlflowObject)
| LoggedModelOutput(model_id: str, step: int) -> None
|
| ModelOutput object associated with a Run.
|
| Method resolution order:
| LoggedModelOutput
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other: mlflow.entities._mlflow_object._MlflowObject) -> bool
| Return self==value.
|
| __init__(self, model_id: str, step: int) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| to_dictionary(self) -> dict[str, str | int]
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| model_id
| Model ID
|
| step
| Step at which the model was logged
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class LoggedModelParameter(mlflow.entities._mlflow_object._MlflowObject)
| LoggedModelParameter(key, value)
|
| MLflow entity representing a parameter of a Model.
|
| Method resolution order:
| LoggedModelParameter
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, _LoggedModelParameter__o)
| Return self==value.
|
| __hash__(self)
| Return hash(self).
|
| __init__(self, key, value)
| Initialize self. See help(type(self)) for accurate signature.
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| key
| String key corresponding to the parameter name.
|
| value
| String value of the parameter.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class LoggedModelStatus(builtins.str, enum.Enum)
| LoggedModelStatus(*values)
|
| Enum for status of an :py:class:`mlflow.entities.LoggedModel`.
|
| Method resolution order:
| LoggedModelStatus
| builtins.str
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec) from enum.Enum
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__(self)
| Return str(self).
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| FAILED = <LoggedModelStatus.FAILED: 'FAILED'>
|
| PENDING = <LoggedModelStatus.PENDING: 'PENDING'>
|
| READY = <LoggedModelStatus.READY: 'READY'>
|
| UNSPECIFIED = <LoggedModelStatus.UNSPECIFIED: 'UNSPECIFIED'>
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.str:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(...)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __sizeof__(self, /)
| Return the size of the string in memory, in bytes.
|
| capitalize(self, /)
| Return a capitalized version of the string.
|
| More specifically, make the first character have upper case and the rest lower
| case.
|
| casefold(self, /)
| Return a version of the string suitable for caseless comparisons.
|
| center(self, width, fillchar=' ', /)
| Return a centered string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| count(...)
| S.count(sub[, start[, end]]) -> int
|
| Return the number of non-overlapping occurrences of substring sub in
| string S[start:end]. Optional arguments start and end are
| interpreted as in slice notation.
|
| encode(self, /, encoding='utf-8', errors='strict')
| Encode the string using the codec registered for encoding.
|
| encoding
| The encoding in which to encode the string.
| errors
| The error handling scheme to use for encoding errors.
| The default is 'strict' meaning that encoding errors raise a
| UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
| 'xmlcharrefreplace' as well as any other name registered with
| codecs.register_error that can handle UnicodeEncodeErrors.
|
| endswith(...)
| S.endswith(suffix[, start[, end]]) -> bool
|
| Return True if S ends with the specified suffix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| suffix can also be a tuple of strings to try.
|
| expandtabs(self, /, tabsize=8)
| Return a copy where all tab characters are expanded using spaces.
|
| If tabsize is not given, a tab size of 8 characters is assumed.
|
| find(...)
| S.find(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| format(...)
| S.format(*args, **kwargs) -> str
|
| Return a formatted version of S, using substitutions from args and kwargs.
| The substitutions are identified by braces ('{' and '}').
|
| format_map(...)
| S.format_map(mapping) -> str
|
| Return a formatted version of S, using substitutions from mapping.
| The substitutions are identified by braces ('{' and '}').
|
| index(...)
| S.index(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| isalnum(self, /)
| Return True if the string is an alpha-numeric string, False otherwise.
|
| A string is alpha-numeric if all characters in the string are alpha-numeric and
| there is at least one character in the string.
|
| isalpha(self, /)
| Return True if the string is an alphabetic string, False otherwise.
|
| A string is alphabetic if all characters in the string are alphabetic and there
| is at least one character in the string.
|
| isascii(self, /)
| Return True if all characters in the string are ASCII, False otherwise.
|
| ASCII characters have code points in the range U+0000-U+007F.
| Empty string is ASCII too.
|
| isdecimal(self, /)
| Return True if the string is a decimal string, False otherwise.
|
| A string is a decimal string if all characters in the string are decimal and
| there is at least one character in the string.
|
| isdigit(self, /)
| Return True if the string is a digit string, False otherwise.
|
| A string is a digit string if all characters in the string are digits and there
| is at least one character in the string.
|
| isidentifier(self, /)
| Return True if the string is a valid Python identifier, False otherwise.
|
| Call keyword.iskeyword(s) to test whether string s is a reserved identifier,
| such as "def" or "class".
|
| islower(self, /)
| Return True if the string is a lowercase string, False otherwise.
|
| A string is lowercase if all cased characters in the string are lowercase and
| there is at least one cased character in the string.
|
| isnumeric(self, /)
| Return True if the string is a numeric string, False otherwise.
|
| A string is numeric if all characters in the string are numeric and there is at
| least one character in the string.
|
| isprintable(self, /)
| Return True if the string is printable, False otherwise.
|
| A string is printable if all of its characters are considered printable in
| repr() or if it is empty.
|
| isspace(self, /)
| Return True if the string is a whitespace string, False otherwise.
|
| A string is whitespace if all characters in the string are whitespace and there
| is at least one character in the string.
|
| istitle(self, /)
| Return True if the string is a title-cased string, False otherwise.
|
| In a title-cased string, upper- and title-case characters may only
| follow uncased characters and lowercase characters only cased ones.
|
| isupper(self, /)
| Return True if the string is an uppercase string, False otherwise.
|
| A string is uppercase if all cased characters in the string are uppercase and
| there is at least one cased character in the string.
|
| join(self, iterable, /)
| Concatenate any number of strings.
|
| The string whose method is called is inserted in between each given string.
| The result is returned as a new string.
|
| Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
|
| ljust(self, width, fillchar=' ', /)
| Return a left-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| lower(self, /)
| Return a copy of the string converted to lowercase.
|
| lstrip(self, chars=None, /)
| Return a copy of the string with leading whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| partition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string. If the separator is found,
| returns a 3-tuple containing the part before the separator, the separator
| itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing the original string
| and two empty strings.
|
| removeprefix(self, prefix, /)
| Return a str with the given prefix string removed if present.
|
| If the string starts with the prefix string, return string[len(prefix):].
| Otherwise, return a copy of the original string.
|
| removesuffix(self, suffix, /)
| Return a str with the given suffix string removed if present.
|
| If the string ends with the suffix string and that suffix is not empty,
| return string[:-len(suffix)]. Otherwise, return a copy of the original
| string.
|
| replace(self, old, new, count=-1, /)
| Return a copy with all occurrences of substring old replaced by new.
|
| count
| Maximum number of occurrences to replace.
| -1 (the default value) means replace all occurrences.
|
| If the optional argument count is given, only the first count occurrences are
| replaced.
|
| rfind(...)
| S.rfind(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| rindex(...)
| S.rindex(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| rjust(self, width, fillchar=' ', /)
| Return a right-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| rpartition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string, starting at the end. If
| the separator is found, returns a 3-tuple containing the part before the
| separator, the separator itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing two empty strings
| and the original string.
|
| rsplit(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the end of the string and works to the front.
|
| rstrip(self, chars=None, /)
| Return a copy of the string with trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| split(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the front of the string and works to the end.
|
| Note, str.split() is mainly useful for data that has been intentionally
| delimited. With natural text that includes punctuation, consider using
| the regular expression module.
|
| splitlines(self, /, keepends=False)
| Return a list of the lines in the string, breaking at line boundaries.
|
| Line breaks are not included in the resulting list unless keepends is given and
| true.
|
| startswith(...)
| S.startswith(prefix[, start[, end]]) -> bool
|
| Return True if S starts with the specified prefix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| prefix can also be a tuple of strings to try.
|
| strip(self, chars=None, /)
| Return a copy of the string with leading and trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| swapcase(self, /)
| Convert uppercase characters to lowercase and lowercase characters to uppercase.
|
| title(self, /)
| Return a version of the string where each word is titlecased.
|
| More specifically, words start with uppercased characters and all remaining
| cased characters have lower case.
|
| translate(self, table, /)
| Replace each character in the string using the given translation table.
|
| table
| Translation table, which must be a mapping of Unicode ordinals to
| Unicode ordinals, strings, or None.
|
| The table must implement lookup/indexing via __getitem__, for instance a
| dictionary or list. If this operation raises LookupError, the character is
| left untouched. Characters mapped to None are deleted.
|
| upper(self, /)
| Return a copy of the string converted to uppercase.
|
| zfill(self, width, /)
| Pad a numeric string with zeros on the left, to fill a field of the given width.
|
| The string is never truncated.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.str:
|
| maketrans(...)
| Return a translation table usable for str.translate().
|
| If there is only one argument, it must be a dictionary mapping Unicode
| ordinals (integers) or characters to Unicode ordinals, strings or None.
| Character keys will be then converted to ordinals.
| If there are two arguments, they must be strings of equal length, and
| in the resulting dictionary, each character in x will be mapped to the
| character at the same position in y. If there is a third argument, it
| must be a string, whose characters will be mapped to None in the result.
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class LoggedModelTag(mlflow.entities._mlflow_object._MlflowObject)
| LoggedModelTag(key, value)
|
| Tag object associated with a Model.
|
| Method resolution order:
| LoggedModelTag
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, key, value)
| Initialize self. See help(type(self)) for accurate signature.
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| key
| String name of the tag.
|
| value
| String value of the tag.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class MCPAccessEndpoint(builtins.object)
| MCPAccessEndpoint(id: 'str', server_name: 'str', url: 'str', transport_type: 'MCPRemoteTransportType' = <MCPRemoteTransportType.STREAMABLE_HTTP: 'streamable-http'>, server_version: 'str | None' = None, server_alias: 'str | None' = None, resolved_version: 'MCPServerVersion | None' = None, workspace: 'str | None' = None, created_by: 'str | None' = None, last_updated_by: 'str | None' = None, creation_timestamp: 'int | None' = None, last_updated_timestamp: 'int | None' = None) -> None
|
| .. Note:: Experimental: This class may change or be removed in a future release without warning.
|
| MCPAccessEndpoint(id: 'str', server_name: 'str', url: 'str', transport_type: 'MCPRemoteTransportType' = <MCPRemoteTransportType.STREAMABLE_HTTP: 'streamable-http'>, server_version: 'str | None' = None, server_alias: 'str | None' = None, resolved_version: 'MCPServerVersion | None' = None, workspace: 'str | None' = None, created_by: 'str | None' = None, last_updated_by: 'str | None' = None, creation_timestamp: 'int | None' = None, last_updated_timestamp: 'int | None' = None)
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, id: 'str', server_name: 'str', url: 'str', transport_type: 'MCPRemoteTransportType' = <MCPRemoteTransportType.STREAMABLE_HTTP: 'streamable-http'>, server_version: 'str | None' = None, server_alias: 'str | None' = None, resolved_version: 'MCPServerVersion | None' = None, workspace: 'str | None' = None, created_by: 'str | None' = None, last_updated_by: 'str | None' = None, creation_timestamp: 'int | None' = None, last_updated_timestamp: 'int | None' = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __post_init__(self)
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dict(data: 'dict[str, Any]') -> 'MCPAccessEndpoint'
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'created_by': 'str | None', 'creation_timestamp': '...
|
| __dataclass_fields__ = {'created_by': Field(name='created_by',type='st...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('id', 'server_name', 'url', 'transport_type', 'serve...
|
| created_by = None
|
| creation_timestamp = None
|
| last_updated_by = None
|
| last_updated_timestamp = None
|
| resolved_version = None
|
| server_alias = None
|
| server_version = None
|
| transport_type = <MCPRemoteTransportType.STREAMABLE_HTTP: 'streamable-...
|
| workspace = None
class MCPRemoteTransportType(builtins.str, enum.Enum)
| MCPRemoteTransportType(*values)
|
| Method resolution order:
| MCPRemoteTransportType
| builtins.str
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec) from enum.Enum
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__(self)
| Return str(self).
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| SSE = <MCPRemoteTransportType.SSE: 'sse'>
|
| STREAMABLE_HTTP = <MCPRemoteTransportType.STREAMABLE_HTTP: 'streamable...
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.str:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(...)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __sizeof__(self, /)
| Return the size of the string in memory, in bytes.
|
| capitalize(self, /)
| Return a capitalized version of the string.
|
| More specifically, make the first character have upper case and the rest lower
| case.
|
| casefold(self, /)
| Return a version of the string suitable for caseless comparisons.
|
| center(self, width, fillchar=' ', /)
| Return a centered string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| count(...)
| S.count(sub[, start[, end]]) -> int
|
| Return the number of non-overlapping occurrences of substring sub in
| string S[start:end]. Optional arguments start and end are
| interpreted as in slice notation.
|
| encode(self, /, encoding='utf-8', errors='strict')
| Encode the string using the codec registered for encoding.
|
| encoding
| The encoding in which to encode the string.
| errors
| The error handling scheme to use for encoding errors.
| The default is 'strict' meaning that encoding errors raise a
| UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
| 'xmlcharrefreplace' as well as any other name registered with
| codecs.register_error that can handle UnicodeEncodeErrors.
|
| endswith(...)
| S.endswith(suffix[, start[, end]]) -> bool
|
| Return True if S ends with the specified suffix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| suffix can also be a tuple of strings to try.
|
| expandtabs(self, /, tabsize=8)
| Return a copy where all tab characters are expanded using spaces.
|
| If tabsize is not given, a tab size of 8 characters is assumed.
|
| find(...)
| S.find(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| format(...)
| S.format(*args, **kwargs) -> str
|
| Return a formatted version of S, using substitutions from args and kwargs.
| The substitutions are identified by braces ('{' and '}').
|
| format_map(...)
| S.format_map(mapping) -> str
|
| Return a formatted version of S, using substitutions from mapping.
| The substitutions are identified by braces ('{' and '}').
|
| index(...)
| S.index(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| isalnum(self, /)
| Return True if the string is an alpha-numeric string, False otherwise.
|
| A string is alpha-numeric if all characters in the string are alpha-numeric and
| there is at least one character in the string.
|
| isalpha(self, /)
| Return True if the string is an alphabetic string, False otherwise.
|
| A string is alphabetic if all characters in the string are alphabetic and there
| is at least one character in the string.
|
| isascii(self, /)
| Return True if all characters in the string are ASCII, False otherwise.
|
| ASCII characters have code points in the range U+0000-U+007F.
| Empty string is ASCII too.
|
| isdecimal(self, /)
| Return True if the string is a decimal string, False otherwise.
|
| A string is a decimal string if all characters in the string are decimal and
| there is at least one character in the string.
|
| isdigit(self, /)
| Return True if the string is a digit string, False otherwise.
|
| A string is a digit string if all characters in the string are digits and there
| is at least one character in the string.
|
| isidentifier(self, /)
| Return True if the string is a valid Python identifier, False otherwise.
|
| Call keyword.iskeyword(s) to test whether string s is a reserved identifier,
| such as "def" or "class".
|
| islower(self, /)
| Return True if the string is a lowercase string, False otherwise.
|
| A string is lowercase if all cased characters in the string are lowercase and
| there is at least one cased character in the string.
|
| isnumeric(self, /)
| Return True if the string is a numeric string, False otherwise.
|
| A string is numeric if all characters in the string are numeric and there is at
| least one character in the string.
|
| isprintable(self, /)
| Return True if the string is printable, False otherwise.
|
| A string is printable if all of its characters are considered printable in
| repr() or if it is empty.
|
| isspace(self, /)
| Return True if the string is a whitespace string, False otherwise.
|
| A string is whitespace if all characters in the string are whitespace and there
| is at least one character in the string.
|
| istitle(self, /)
| Return True if the string is a title-cased string, False otherwise.
|
| In a title-cased string, upper- and title-case characters may only
| follow uncased characters and lowercase characters only cased ones.
|
| isupper(self, /)
| Return True if the string is an uppercase string, False otherwise.
|
| A string is uppercase if all cased characters in the string are uppercase and
| there is at least one cased character in the string.
|
| join(self, iterable, /)
| Concatenate any number of strings.
|
| The string whose method is called is inserted in between each given string.
| The result is returned as a new string.
|
| Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
|
| ljust(self, width, fillchar=' ', /)
| Return a left-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| lower(self, /)
| Return a copy of the string converted to lowercase.
|
| lstrip(self, chars=None, /)
| Return a copy of the string with leading whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| partition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string. If the separator is found,
| returns a 3-tuple containing the part before the separator, the separator
| itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing the original string
| and two empty strings.
|
| removeprefix(self, prefix, /)
| Return a str with the given prefix string removed if present.
|
| If the string starts with the prefix string, return string[len(prefix):].
| Otherwise, return a copy of the original string.
|
| removesuffix(self, suffix, /)
| Return a str with the given suffix string removed if present.
|
| If the string ends with the suffix string and that suffix is not empty,
| return string[:-len(suffix)]. Otherwise, return a copy of the original
| string.
|
| replace(self, old, new, count=-1, /)
| Return a copy with all occurrences of substring old replaced by new.
|
| count
| Maximum number of occurrences to replace.
| -1 (the default value) means replace all occurrences.
|
| If the optional argument count is given, only the first count occurrences are
| replaced.
|
| rfind(...)
| S.rfind(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| rindex(...)
| S.rindex(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| rjust(self, width, fillchar=' ', /)
| Return a right-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| rpartition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string, starting at the end. If
| the separator is found, returns a 3-tuple containing the part before the
| separator, the separator itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing two empty strings
| and the original string.
|
| rsplit(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the end of the string and works to the front.
|
| rstrip(self, chars=None, /)
| Return a copy of the string with trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| split(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the front of the string and works to the end.
|
| Note, str.split() is mainly useful for data that has been intentionally
| delimited. With natural text that includes punctuation, consider using
| the regular expression module.
|
| splitlines(self, /, keepends=False)
| Return a list of the lines in the string, breaking at line boundaries.
|
| Line breaks are not included in the resulting list unless keepends is given and
| true.
|
| startswith(...)
| S.startswith(prefix[, start[, end]]) -> bool
|
| Return True if S starts with the specified prefix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| prefix can also be a tuple of strings to try.
|
| strip(self, chars=None, /)
| Return a copy of the string with leading and trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| swapcase(self, /)
| Convert uppercase characters to lowercase and lowercase characters to uppercase.
|
| title(self, /)
| Return a version of the string where each word is titlecased.
|
| More specifically, words start with uppercased characters and all remaining
| cased characters have lower case.
|
| translate(self, table, /)
| Replace each character in the string using the given translation table.
|
| table
| Translation table, which must be a mapping of Unicode ordinals to
| Unicode ordinals, strings, or None.
|
| The table must implement lookup/indexing via __getitem__, for instance a
| dictionary or list. If this operation raises LookupError, the character is
| left untouched. Characters mapped to None are deleted.
|
| upper(self, /)
| Return a copy of the string converted to uppercase.
|
| zfill(self, width, /)
| Pad a numeric string with zeros on the left, to fill a field of the given width.
|
| The string is never truncated.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.str:
|
| maketrans(...)
| Return a translation table usable for str.translate().
|
| If there is only one argument, it must be a dictionary mapping Unicode
| ordinals (integers) or characters to Unicode ordinals, strings or None.
| Character keys will be then converted to ordinals.
| If there are two arguments, they must be strings of equal length, and
| in the resulting dictionary, each character in x will be mapped to the
| character at the same position in y. If there is a third argument, it
| must be a string, whose characters will be mapped to None in the result.
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class MCPServer(builtins.object)
| MCPServer(name: 'str', display_name: 'str | None' = None, description: 'str | None' = None, icons: 'list[dict[str, Any]] | None' = None, workspace: 'str | None' = None, status: 'MCPStatus | None' = None, tags: 'dict[str, str]' = <factory>, aliases: 'dict[str, str]' = <factory>, access_endpoints: 'list[MCPAccessEndpoint]' = <factory>, latest_version: 'str | None' = None, created_by: 'str | None' = None, last_updated_by: 'str | None' = None, creation_timestamp: 'int | None' = None, last_updated_timestamp: 'int | None' = None) -> None
|
| .. Note:: Experimental: This class may change or be removed in a future release without warning.
|
| MCPServer(name: 'str', display_name: 'str | None' = None, description: 'str | None' = None, icons: 'list[dict[str, Any]] | None' = None, workspace: 'str | None' = None, status: 'MCPStatus | None' = None, tags: 'dict[str, str]' = <factory>, aliases: 'dict[str, str]' = <factory>, access_endpoints: 'list[MCPAccessEndpoint]' = <factory>, latest_version: 'str | None' = None, created_by: 'str | None' = None, last_updated_by: 'str | None' = None, creation_timestamp: 'int | None' = None, last_updated_timestamp: 'int | None' = None)
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, name: 'str', display_name: 'str | None' = None, description: 'str | None' = None, icons: 'list[dict[str, Any]] | None' = None, workspace: 'str | None' = None, status: 'MCPStatus | None' = None, tags: 'dict[str, str]' = <factory>, aliases: 'dict[str, str]' = <factory>, access_endpoints: 'list[MCPAccessEndpoint]' = <factory>, latest_version: 'str | None' = None, created_by: 'str | None' = None, last_updated_by: 'str | None' = None, creation_timestamp: 'int | None' = None, last_updated_timestamp: 'int | None' = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __post_init__(self)
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dict(data: 'dict[str, Any]') -> 'MCPServer'
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'access_endpoints': 'list[MCPAccessEndpoint]', 'ali...
|
| __dataclass_fields__ = {'access_endpoints': Field(name='access_endpoin...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('name', 'display_name', 'description', 'icons', 'wor...
|
| created_by = None
|
| creation_timestamp = None
|
| description = None
|
| display_name = None
|
| icons = None
|
| last_updated_by = None
|
| last_updated_timestamp = None
|
| latest_version = None
|
| status = None
|
| workspace = None
class MCPServerVersion(builtins.object)
| MCPServerVersion(name: 'str', version: 'str', server_json: 'dict[str, Any]', status: 'MCPStatus' = <MCPStatus.DRAFT: 'draft'>, tools: 'list[MCPTool] | None' = None, aliases: 'list[str]' = <factory>, tags: 'dict[str, str]' = <factory>, connect_options: 'dict[str, ConnectOptionSettings]' = <factory>, source: 'str | None' = None, workspace: 'str | None' = None, created_by: 'str | None' = None, last_updated_by: 'str | None' = None, creation_timestamp: 'int | None' = None, last_updated_timestamp: 'int | None' = None) -> None
|
| .. Note:: Experimental: This class may change or be removed in a future release without warning.
|
| MCPServerVersion(name: 'str', version: 'str', server_json: 'dict[str, Any]', status: 'MCPStatus' = <MCPStatus.DRAFT: 'draft'>, tools: 'list[MCPTool] | None' = None, aliases: 'list[str]' = <factory>, tags: 'dict[str, str]' = <factory>, connect_options: 'dict[str, ConnectOptionSettings]' = <factory>, source: 'str | None' = None, workspace: 'str | None' = None, created_by: 'str | None' = None, last_updated_by: 'str | None' = None, creation_timestamp: 'int | None' = None, last_updated_timestamp: 'int | None' = None)
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, name: 'str', version: 'str', server_json: 'dict[str, Any]', status: 'MCPStatus' = <MCPStatus.DRAFT: 'draft'>, tools: 'list[MCPTool] | None' = None, aliases: 'list[str]' = <factory>, tags: 'dict[str, str]' = <factory>, connect_options: 'dict[str, ConnectOptionSettings]' = <factory>, source: 'str | None' = None, workspace: 'str | None' = None, created_by: 'str | None' = None, last_updated_by: 'str | None' = None, creation_timestamp: 'int | None' = None, last_updated_timestamp: 'int | None' = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __post_init__(self)
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dict(data: 'dict[str, Any]') -> 'MCPServerVersion'
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'aliases': 'list[str]', 'connect_options': 'dict[st...
|
| __dataclass_fields__ = {'aliases': Field(name='aliases',type='list[str...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('name', 'version', 'server_json', 'status', 'tools',...
|
| created_by = None
|
| creation_timestamp = None
|
| last_updated_by = None
|
| last_updated_timestamp = None
|
| source = None
|
| status = <MCPStatus.DRAFT: 'draft'>
|
| tools = None
|
| workspace = None
class MCPStatus(builtins.str, enum.Enum)
| MCPStatus(*values)
|
| Method resolution order:
| MCPStatus
| builtins.str
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec) from enum.Enum
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__(self)
| Return str(self).
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| ACTIVE = <MCPStatus.ACTIVE: 'active'>
|
| DELETED = <MCPStatus.DELETED: 'deleted'>
|
| DEPRECATED = <MCPStatus.DEPRECATED: 'deprecated'>
|
| DRAFT = <MCPStatus.DRAFT: 'draft'>
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.str:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(...)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __sizeof__(self, /)
| Return the size of the string in memory, in bytes.
|
| capitalize(self, /)
| Return a capitalized version of the string.
|
| More specifically, make the first character have upper case and the rest lower
| case.
|
| casefold(self, /)
| Return a version of the string suitable for caseless comparisons.
|
| center(self, width, fillchar=' ', /)
| Return a centered string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| count(...)
| S.count(sub[, start[, end]]) -> int
|
| Return the number of non-overlapping occurrences of substring sub in
| string S[start:end]. Optional arguments start and end are
| interpreted as in slice notation.
|
| encode(self, /, encoding='utf-8', errors='strict')
| Encode the string using the codec registered for encoding.
|
| encoding
| The encoding in which to encode the string.
| errors
| The error handling scheme to use for encoding errors.
| The default is 'strict' meaning that encoding errors raise a
| UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
| 'xmlcharrefreplace' as well as any other name registered with
| codecs.register_error that can handle UnicodeEncodeErrors.
|
| endswith(...)
| S.endswith(suffix[, start[, end]]) -> bool
|
| Return True if S ends with the specified suffix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| suffix can also be a tuple of strings to try.
|
| expandtabs(self, /, tabsize=8)
| Return a copy where all tab characters are expanded using spaces.
|
| If tabsize is not given, a tab size of 8 characters is assumed.
|
| find(...)
| S.find(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| format(...)
| S.format(*args, **kwargs) -> str
|
| Return a formatted version of S, using substitutions from args and kwargs.
| The substitutions are identified by braces ('{' and '}').
|
| format_map(...)
| S.format_map(mapping) -> str
|
| Return a formatted version of S, using substitutions from mapping.
| The substitutions are identified by braces ('{' and '}').
|
| index(...)
| S.index(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| isalnum(self, /)
| Return True if the string is an alpha-numeric string, False otherwise.
|
| A string is alpha-numeric if all characters in the string are alpha-numeric and
| there is at least one character in the string.
|
| isalpha(self, /)
| Return True if the string is an alphabetic string, False otherwise.
|
| A string is alphabetic if all characters in the string are alphabetic and there
| is at least one character in the string.
|
| isascii(self, /)
| Return True if all characters in the string are ASCII, False otherwise.
|
| ASCII characters have code points in the range U+0000-U+007F.
| Empty string is ASCII too.
|
| isdecimal(self, /)
| Return True if the string is a decimal string, False otherwise.
|
| A string is a decimal string if all characters in the string are decimal and
| there is at least one character in the string.
|
| isdigit(self, /)
| Return True if the string is a digit string, False otherwise.
|
| A string is a digit string if all characters in the string are digits and there
| is at least one character in the string.
|
| isidentifier(self, /)
| Return True if the string is a valid Python identifier, False otherwise.
|
| Call keyword.iskeyword(s) to test whether string s is a reserved identifier,
| such as "def" or "class".
|
| islower(self, /)
| Return True if the string is a lowercase string, False otherwise.
|
| A string is lowercase if all cased characters in the string are lowercase and
| there is at least one cased character in the string.
|
| isnumeric(self, /)
| Return True if the string is a numeric string, False otherwise.
|
| A string is numeric if all characters in the string are numeric and there is at
| least one character in the string.
|
| isprintable(self, /)
| Return True if the string is printable, False otherwise.
|
| A string is printable if all of its characters are considered printable in
| repr() or if it is empty.
|
| isspace(self, /)
| Return True if the string is a whitespace string, False otherwise.
|
| A string is whitespace if all characters in the string are whitespace and there
| is at least one character in the string.
|
| istitle(self, /)
| Return True if the string is a title-cased string, False otherwise.
|
| In a title-cased string, upper- and title-case characters may only
| follow uncased characters and lowercase characters only cased ones.
|
| isupper(self, /)
| Return True if the string is an uppercase string, False otherwise.
|
| A string is uppercase if all cased characters in the string are uppercase and
| there is at least one cased character in the string.
|
| join(self, iterable, /)
| Concatenate any number of strings.
|
| The string whose method is called is inserted in between each given string.
| The result is returned as a new string.
|
| Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
|
| ljust(self, width, fillchar=' ', /)
| Return a left-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| lower(self, /)
| Return a copy of the string converted to lowercase.
|
| lstrip(self, chars=None, /)
| Return a copy of the string with leading whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| partition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string. If the separator is found,
| returns a 3-tuple containing the part before the separator, the separator
| itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing the original string
| and two empty strings.
|
| removeprefix(self, prefix, /)
| Return a str with the given prefix string removed if present.
|
| If the string starts with the prefix string, return string[len(prefix):].
| Otherwise, return a copy of the original string.
|
| removesuffix(self, suffix, /)
| Return a str with the given suffix string removed if present.
|
| If the string ends with the suffix string and that suffix is not empty,
| return string[:-len(suffix)]. Otherwise, return a copy of the original
| string.
|
| replace(self, old, new, count=-1, /)
| Return a copy with all occurrences of substring old replaced by new.
|
| count
| Maximum number of occurrences to replace.
| -1 (the default value) means replace all occurrences.
|
| If the optional argument count is given, only the first count occurrences are
| replaced.
|
| rfind(...)
| S.rfind(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| rindex(...)
| S.rindex(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| rjust(self, width, fillchar=' ', /)
| Return a right-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| rpartition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string, starting at the end. If
| the separator is found, returns a 3-tuple containing the part before the
| separator, the separator itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing two empty strings
| and the original string.
|
| rsplit(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the end of the string and works to the front.
|
| rstrip(self, chars=None, /)
| Return a copy of the string with trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| split(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the front of the string and works to the end.
|
| Note, str.split() is mainly useful for data that has been intentionally
| delimited. With natural text that includes punctuation, consider using
| the regular expression module.
|
| splitlines(self, /, keepends=False)
| Return a list of the lines in the string, breaking at line boundaries.
|
| Line breaks are not included in the resulting list unless keepends is given and
| true.
|
| startswith(...)
| S.startswith(prefix[, start[, end]]) -> bool
|
| Return True if S starts with the specified prefix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| prefix can also be a tuple of strings to try.
|
| strip(self, chars=None, /)
| Return a copy of the string with leading and trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| swapcase(self, /)
| Convert uppercase characters to lowercase and lowercase characters to uppercase.
|
| title(self, /)
| Return a version of the string where each word is titlecased.
|
| More specifically, words start with uppercased characters and all remaining
| cased characters have lower case.
|
| translate(self, table, /)
| Replace each character in the string using the given translation table.
|
| table
| Translation table, which must be a mapping of Unicode ordinals to
| Unicode ordinals, strings, or None.
|
| The table must implement lookup/indexing via __getitem__, for instance a
| dictionary or list. If this operation raises LookupError, the character is
| left untouched. Characters mapped to None are deleted.
|
| upper(self, /)
| Return a copy of the string converted to uppercase.
|
| zfill(self, width, /)
| Pad a numeric string with zeros on the left, to fill a field of the given width.
|
| The string is never truncated.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.str:
|
| maketrans(...)
| Return a translation table usable for str.translate().
|
| If there is only one argument, it must be a dictionary mapping Unicode
| ordinals (integers) or characters to Unicode ordinals, strings or None.
| Character keys will be then converted to ordinals.
| If there are two arguments, they must be strings of equal length, and
| in the resulting dictionary, each character in x will be mapped to the
| character at the same position in y. If there is a third argument, it
| must be a string, whose characters will be mapped to None in the result.
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class MCPTool(builtins.object)
| MCPTool(name: 'str', title: 'str | None' = None, description: 'str | None' = None, input_schema: 'dict[str, Any] | None' = None, output_schema: 'dict[str, Any] | None' = None, annotations: 'dict[str, Any] | None' = None, icons: 'list[dict[str, Any]] | None' = None, execution: 'dict[str, Any] | None' = None) -> None
|
| .. Note:: Experimental: This class may change or be removed in a future release without warning.
|
| MCPTool(name: 'str', title: 'str | None' = None, description: 'str | None' = None, input_schema: 'dict[str, Any] | None' = None, output_schema: 'dict[str, Any] | None' = None, annotations: 'dict[str, Any] | None' = None, icons: 'list[dict[str, Any]] | None' = None, execution: 'dict[str, Any] | None' = None)
|
| Methods defined here:
|
| __delattr__(self, name)
| Implement delattr(self, name).
|
| __eq__(self, other)
| Return self==value.
|
| __hash__(self)
| Return hash(self).
|
| __init__(self, name: 'str', title: 'str | None' = None, description: 'str | None' = None, input_schema: 'dict[str, Any] | None' = None, output_schema: 'dict[str, Any] | None' = None, annotations: 'dict[str, Any] | None' = None, icons: 'list[dict[str, Any]] | None' = None, execution: 'dict[str, Any] | None' = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| __setattr__(self, name, value)
| Implement setattr(self, name, value).
|
| to_dict(self) -> 'dict[str, Any]'
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dict(data: 'dict[str, Any]') -> 'MCPTool'
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'annotations': 'dict[str, Any] | None', 'descriptio...
|
| __dataclass_fields__ = {'annotations': Field(name='annotations',type='...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __match_args__ = ('name', 'title', 'description', 'input_schema', 'out...
|
| annotations = None
|
| description = None
|
| execution = None
|
| icons = None
|
| input_schema = None
|
| output_schema = None
|
| title = None
class Metric(mlflow.entities._mlflow_object._MlflowObject)
| Metric(key, value, timestamp, step, model_id: str | None = None, dataset_name: str | None = None, dataset_digest: str | None = None, run_id: str | None = None)
|
| Metric object.
|
| Method resolution order:
| Metric
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, _Metric__o)
| Return self==value.
|
| __hash__(self)
| Return hash(self).
|
| __init__(self, key, value, timestamp, step, model_id: str | None = None, dataset_name: str | None = None, dataset_digest: str | None = None, run_id: str | None = None)
| Initialize self. See help(type(self)) for accurate signature.
|
| to_dictionary(self)
| Convert the Metric object to a dictionary.
|
| Returns:
| dict: The Metric object represented as a dictionary.
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dictionary(metric_dict)
| Create a Metric object from a dictionary.
|
| Args:
| metric_dict (dict): Dictionary containing metric information.
|
| Returns:
| Metric: The Metric object created from the dictionary.
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| dataset_digest
| String. Digest of the dataset associated with the metric.
|
| dataset_name
| String. Name of the dataset associated with the metric.
|
| key
| String key corresponding to the metric name.
|
| model_id
| ID of the Model associated with the metric.
|
| run_id
| String. Run ID associated with the metric.
|
| step
| Integer metric step (x-coordinate).
|
| timestamp
| Metric timestamp as an integer (milliseconds since the Unix epoch).
|
| value
| Float value of the metric.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class MlflowExperimentLocation(TraceLocationBase)
| MlflowExperimentLocation(experiment_id: str) -> None
|
| Represents the location of an MLflow experiment.
|
| Args:
| experiment_id: The ID of the MLflow experiment where the trace is stored.
|
| Method resolution order:
| MlflowExperimentLocation
| TraceLocationBase
| mlflow.entities._mlflow_object._MlflowObject
| abc.ABC
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, experiment_id: str) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| to_dict(self) -> dict[str, typing.Any]
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dict(d: dict[str, typing.Any]) -> 'MlflowExperimentLocation'
|
| from_proto(proto) -> 'MlflowExperimentLocation'
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset()
|
| __annotations__ = {'experiment_id': <class 'str'>}
|
| __dataclass_fields__ = {'experiment_id': Field(name='experiment_id',ty...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('experiment_id',)
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class NoOpSpan(Span)
| NoOpSpan(otel_span=None)
|
| No-op implementation of the Span interface.
|
| Returned when span creation fails or when the span is dropped by the
| sampler. An optional ``otel_span`` can be provided to preserve the
| underlying OTel span context so that child spans inherit the same
| trace ID and sampling decision.
|
| E.g.
|
| .. code-block:: python
|
| with mlflow.start_span("span_name") as span:
| # Even if the span creation fails, the following calls should pass.
| span.set_inputs({"x": 1})
| # Do something
|
| Method resolution order:
| NoOpSpan
| Span
| builtins.object
|
| Methods defined here:
|
| __init__(self, otel_span=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| add_event(self, event: mlflow.entities.span_event.SpanEvent)
|
| add_link(self, link: mlflow.entities.link.Link) -> None
|
| end(self, outputs: typing.Any | None = None, attributes: dict[str, typing.Any] | None = None, status: mlflow.entities.span_status.SpanStatus | str | None = None, end_time_ns: int | None = None)
|
| record_exception(self, exception: str | Exception)
|
| set_attribute(self, key: str, value: Any)
|
| set_attributes(self, attributes: dict[str, typing.Any])
|
| set_inputs(self, inputs: dict[str, typing.Any])
|
| set_log_level(self, level: mlflow.entities.span_log_level.SpanLogLevel | int | str)
|
| set_outputs(self, outputs: dict[str, typing.Any])
|
| set_status(self, status: mlflow.entities.span_status.SpanStatus)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| context
|
| end_time_ns
| The end time of the span in nanosecond.
|
| name
| The name of the span.
|
| parent_id
| The span ID of the parent span.
|
| span_id
| The ID of the span. This is only unique within a trace.
|
| start_time_ns
| The start time of the span in nanosecond.
|
| status
| The status of the span.
|
| trace_id
| No-op span returns a special trace ID to distinguish it from the real spans.
|
| ----------------------------------------------------------------------
| Methods inherited from Span:
|
| __repr__(self)
| Return repr(self).
|
| get_attribute(self, key: str) -> typing.Any | None
| Get a single attribute value from the span.
|
| Args:
| key: The key of the attribute to get.
|
| Returns:
| The value of the attribute if it exists, otherwise None.
|
| to_dict(self) -> dict[str, typing.Any]
|
| to_otel_proto(self) -> opentelemetry.proto.trace.v1.trace_pb2.Span
| Convert to OpenTelemetry protobuf span format for OTLP export.
| This is an internal method used by the REST store for logging spans.
|
| Returns:
| An OpenTelemetry protobuf Span message.
|
| ----------------------------------------------------------------------
| Class methods inherited from Span:
|
| from_dict(data: dict[str, typing.Any]) -> 'Span'
| Create a Span object from the given dictionary.
|
| from_dict_v2(data: dict[str, typing.Any]) -> 'Span'
| Create a Span object from the given dictionary in v2 schema.
|
| from_otel_proto(otel_proto_span: opentelemetry.proto.trace.v1.trace_pb2.Span, location_id: str | None = None, *, preserve_request_id: bool = False, resource: opentelemetry.proto.resource.v1.resource_pb2.Resource | None = None) -> 'Span'
| Create a Span from an OpenTelemetry protobuf span.
|
| This is an internal method used for receiving spans via OTel protocol. By default,
| MLflow derives the canonical ``mlflow.traceRequestId`` from the OTLP trace ID so server
| ingest does not trust a client-sent request ID. Set ``preserve_request_id=True`` only for
| trusted internal round-trip flows, such as archived trace payload deserialization, where
| the stored MLflow request ID must be preserved exactly if present.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Span:
|
| attributes
| Get all attributes of the span.
|
| Returns:
| A dictionary of all attributes of the span.
|
| events
| Get all events of the span.
|
| Returns:
| A list of all events of the span.
|
| inputs
| The input values of the span.
|
| links
| Get all links of the span.
|
| Returns:
| A list of all links of the span.
|
| llm_cost
| The cost information for the span in USD.
|
| Returns a dictionary with keys:
| - input_cost: Cost of input tokens
| - output_cost: Cost of output tokens
| - total_cost: Total cost (input + output)
|
| Returns None if cost information is not available.
|
| log_level
| The severity level of the span, or ``None`` if it was not classified.
|
| Set on a :py:class:`LiveSpan <mlflow.entities.LiveSpan>` via
| :py:meth:`set_log_level <mlflow.entities.LiveSpan.set_log_level>`,
| the ``log_level`` argument of :py:func:`mlflow.start_span`,
| :py:func:`mlflow.start_span_no_context`, or :py:func:`mlflow.trace`,
| or by an autologging integration on the user's behalf.
|
| model_name
| The model name used in the span.
|
| outputs
| The output values of the span.
|
| request_id
| Deprecated. Use `trace_id` instead.
|
| span_type
| The type of the span.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Span:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class Param(mlflow.entities._mlflow_object._MlflowObject)
| Param(key, value)
|
| Parameter object.
|
| Method resolution order:
| Param
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, _Param__o)
| Return self==value.
|
| __hash__(self)
| Return hash(self).
|
| __init__(self, key, value)
| Initialize self. See help(type(self)) for accurate signature.
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| key
| String key corresponding to the parameter name.
|
| value
| String value of the parameter.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class Prompt(builtins.object)
| Prompt(name: str, description: str | None = None, creation_timestamp: int | None = None, tags: dict[str, str] | None = None)
|
| Entity representing a prompt in the MLflow Model Registry.
|
| This contains prompt-level information (name, description, tags) but not version-specific
| content. To access version-specific content like the template, use PromptVersion.
|
| Methods defined here:
|
| __eq__(self, other) -> bool
| Return self==value.
|
| __init__(self, name: str, description: str | None = None, creation_timestamp: int | None = None, tags: dict[str, str] | None = None)
| Construct a Prompt entity.
|
| Args:
| name: Name of the prompt.
| description: Description of the prompt.
| creation_timestamp: Timestamp when the prompt was created.
| tags: Prompt-level metadata as key-value pairs.
|
| __repr__(self) -> str
| Return repr(self).
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| creation_timestamp
| The creation timestamp of the prompt.
|
| description
| The description of the prompt.
|
| name
| The name of the prompt.
|
| tags
| Prompt-level metadata as key-value pairs.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __hash__ = None
class RoutingStrategy(builtins.str, enum.Enum)
| RoutingStrategy(*values)
|
| Routing strategy for gateway endpoints.
|
| Method resolution order:
| RoutingStrategy
| builtins.str
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec) from enum.Enum
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__(self) from enum.Enum
| Return str(self).
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| REQUEST_BASED_TRAFFIC_SPLIT = <RoutingStrategy.REQUEST_BASED_TRAFFIC_S...
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.str:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(...)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __sizeof__(self, /)
| Return the size of the string in memory, in bytes.
|
| capitalize(self, /)
| Return a capitalized version of the string.
|
| More specifically, make the first character have upper case and the rest lower
| case.
|
| casefold(self, /)
| Return a version of the string suitable for caseless comparisons.
|
| center(self, width, fillchar=' ', /)
| Return a centered string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| count(...)
| S.count(sub[, start[, end]]) -> int
|
| Return the number of non-overlapping occurrences of substring sub in
| string S[start:end]. Optional arguments start and end are
| interpreted as in slice notation.
|
| encode(self, /, encoding='utf-8', errors='strict')
| Encode the string using the codec registered for encoding.
|
| encoding
| The encoding in which to encode the string.
| errors
| The error handling scheme to use for encoding errors.
| The default is 'strict' meaning that encoding errors raise a
| UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
| 'xmlcharrefreplace' as well as any other name registered with
| codecs.register_error that can handle UnicodeEncodeErrors.
|
| endswith(...)
| S.endswith(suffix[, start[, end]]) -> bool
|
| Return True if S ends with the specified suffix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| suffix can also be a tuple of strings to try.
|
| expandtabs(self, /, tabsize=8)
| Return a copy where all tab characters are expanded using spaces.
|
| If tabsize is not given, a tab size of 8 characters is assumed.
|
| find(...)
| S.find(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| format(...)
| S.format(*args, **kwargs) -> str
|
| Return a formatted version of S, using substitutions from args and kwargs.
| The substitutions are identified by braces ('{' and '}').
|
| format_map(...)
| S.format_map(mapping) -> str
|
| Return a formatted version of S, using substitutions from mapping.
| The substitutions are identified by braces ('{' and '}').
|
| index(...)
| S.index(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| isalnum(self, /)
| Return True if the string is an alpha-numeric string, False otherwise.
|
| A string is alpha-numeric if all characters in the string are alpha-numeric and
| there is at least one character in the string.
|
| isalpha(self, /)
| Return True if the string is an alphabetic string, False otherwise.
|
| A string is alphabetic if all characters in the string are alphabetic and there
| is at least one character in the string.
|
| isascii(self, /)
| Return True if all characters in the string are ASCII, False otherwise.
|
| ASCII characters have code points in the range U+0000-U+007F.
| Empty string is ASCII too.
|
| isdecimal(self, /)
| Return True if the string is a decimal string, False otherwise.
|
| A string is a decimal string if all characters in the string are decimal and
| there is at least one character in the string.
|
| isdigit(self, /)
| Return True if the string is a digit string, False otherwise.
|
| A string is a digit string if all characters in the string are digits and there
| is at least one character in the string.
|
| isidentifier(self, /)
| Return True if the string is a valid Python identifier, False otherwise.
|
| Call keyword.iskeyword(s) to test whether string s is a reserved identifier,
| such as "def" or "class".
|
| islower(self, /)
| Return True if the string is a lowercase string, False otherwise.
|
| A string is lowercase if all cased characters in the string are lowercase and
| there is at least one cased character in the string.
|
| isnumeric(self, /)
| Return True if the string is a numeric string, False otherwise.
|
| A string is numeric if all characters in the string are numeric and there is at
| least one character in the string.
|
| isprintable(self, /)
| Return True if the string is printable, False otherwise.
|
| A string is printable if all of its characters are considered printable in
| repr() or if it is empty.
|
| isspace(self, /)
| Return True if the string is a whitespace string, False otherwise.
|
| A string is whitespace if all characters in the string are whitespace and there
| is at least one character in the string.
|
| istitle(self, /)
| Return True if the string is a title-cased string, False otherwise.
|
| In a title-cased string, upper- and title-case characters may only
| follow uncased characters and lowercase characters only cased ones.
|
| isupper(self, /)
| Return True if the string is an uppercase string, False otherwise.
|
| A string is uppercase if all cased characters in the string are uppercase and
| there is at least one cased character in the string.
|
| join(self, iterable, /)
| Concatenate any number of strings.
|
| The string whose method is called is inserted in between each given string.
| The result is returned as a new string.
|
| Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
|
| ljust(self, width, fillchar=' ', /)
| Return a left-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| lower(self, /)
| Return a copy of the string converted to lowercase.
|
| lstrip(self, chars=None, /)
| Return a copy of the string with leading whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| partition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string. If the separator is found,
| returns a 3-tuple containing the part before the separator, the separator
| itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing the original string
| and two empty strings.
|
| removeprefix(self, prefix, /)
| Return a str with the given prefix string removed if present.
|
| If the string starts with the prefix string, return string[len(prefix):].
| Otherwise, return a copy of the original string.
|
| removesuffix(self, suffix, /)
| Return a str with the given suffix string removed if present.
|
| If the string ends with the suffix string and that suffix is not empty,
| return string[:-len(suffix)]. Otherwise, return a copy of the original
| string.
|
| replace(self, old, new, count=-1, /)
| Return a copy with all occurrences of substring old replaced by new.
|
| count
| Maximum number of occurrences to replace.
| -1 (the default value) means replace all occurrences.
|
| If the optional argument count is given, only the first count occurrences are
| replaced.
|
| rfind(...)
| S.rfind(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| rindex(...)
| S.rindex(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| rjust(self, width, fillchar=' ', /)
| Return a right-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| rpartition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string, starting at the end. If
| the separator is found, returns a 3-tuple containing the part before the
| separator, the separator itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing two empty strings
| and the original string.
|
| rsplit(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the end of the string and works to the front.
|
| rstrip(self, chars=None, /)
| Return a copy of the string with trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| split(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the front of the string and works to the end.
|
| Note, str.split() is mainly useful for data that has been intentionally
| delimited. With natural text that includes punctuation, consider using
| the regular expression module.
|
| splitlines(self, /, keepends=False)
| Return a list of the lines in the string, breaking at line boundaries.
|
| Line breaks are not included in the resulting list unless keepends is given and
| true.
|
| startswith(...)
| S.startswith(prefix[, start[, end]]) -> bool
|
| Return True if S starts with the specified prefix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| prefix can also be a tuple of strings to try.
|
| strip(self, chars=None, /)
| Return a copy of the string with leading and trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| swapcase(self, /)
| Convert uppercase characters to lowercase and lowercase characters to uppercase.
|
| title(self, /)
| Return a version of the string where each word is titlecased.
|
| More specifically, words start with uppercased characters and all remaining
| cased characters have lower case.
|
| translate(self, table, /)
| Replace each character in the string using the given translation table.
|
| table
| Translation table, which must be a mapping of Unicode ordinals to
| Unicode ordinals, strings, or None.
|
| The table must implement lookup/indexing via __getitem__, for instance a
| dictionary or list. If this operation raises LookupError, the character is
| left untouched. Characters mapped to None are deleted.
|
| upper(self, /)
| Return a copy of the string converted to uppercase.
|
| zfill(self, width, /)
| Pad a numeric string with zeros on the left, to fill a field of the given width.
|
| The string is never truncated.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.str:
|
| maketrans(...)
| Return a translation table usable for str.translate().
|
| If there is only one argument, it must be a dictionary mapping Unicode
| ordinals (integers) or characters to Unicode ordinals, strings or None.
| Character keys will be then converted to ordinals.
| If there are two arguments, they must be strings of equal length, and
| in the resulting dictionary, each character in x will be mapped to the
| character at the same position in y. If there is a third argument, it
| must be a string, whose characters will be mapped to None in the result.
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class Run(mlflow.entities._mlflow_object._MlflowObject)
| Run(run_info: mlflow.entities.run_info.RunInfo, run_data: mlflow.entities.run_data.RunData, run_inputs: mlflow.entities.run_inputs.RunInputs | None = None, run_outputs: mlflow.entities.run_outputs.RunOutputs | None = None) -> None
|
| Run object.
|
| Method resolution order:
| Run
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __init__(self, run_info: mlflow.entities.run_info.RunInfo, run_data: mlflow.entities.run_data.RunData, run_inputs: mlflow.entities.run_inputs.RunInputs | None = None, run_outputs: mlflow.entities.run_outputs.RunOutputs | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| to_dictionary(self) -> dict[typing.Any, typing.Any]
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| data
| The run data, including metrics, parameters, and tags.
|
| :rtype: :py:class:`mlflow.entities.RunData`
|
| info
| The run metadata, such as the run id, start time, and status.
|
| :rtype: :py:class:`mlflow.entities.RunInfo`
|
| inputs
| The run inputs, including dataset inputs.
|
| :rtype: :py:class:`mlflow.entities.RunInputs`
|
| outputs
| The run outputs, including model outputs.
|
| :rtype: :py:class:`mlflow.entities.RunOutputs`
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class RunData(mlflow.entities._mlflow_object._MlflowObject)
| RunData(metrics=None, params=None, tags=None)
|
| Run data (metrics and parameters).
|
| Method resolution order:
| RunData
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __init__(self, metrics=None, params=None, tags=None)
| Construct a new mlflow.entities.RunData instance.
|
| Args:
| metrics: List of mlflow.entities.Metric.
| params: List of mlflow.entities.Param.
| tags: List of mlflow.entities.RunTag.
|
| to_dictionary(self)
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| metrics
| Dictionary of string key -> metric value for the current run.
| For each metric key, the metric value with the latest timestamp is returned. In case there
| are multiple values with the same latest timestamp, the maximum of these values is returned.
|
| params
| Dictionary of param key (string) -> param value for the current run.
|
| tags
| Dictionary of tag key (string) -> tag value for the current run.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class RunInfo(mlflow.entities._mlflow_object._MlflowObject)
| RunInfo(run_id, experiment_id, user_id, status, start_time, end_time, lifecycle_stage, artifact_uri=None, run_name=None)
|
| Metadata about a run.
|
| Method resolution order:
| RunInfo
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, run_id, experiment_id, user_id, status, start_time, end_time, lifecycle_stage, artifact_uri=None, run_name=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
|
| get_orderable_attributes()
|
| get_searchable_attributes()
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| artifact_uri
| String root artifact URI of the run.
|
| end_time
| End time of the run, in number of milliseconds since the UNIX epoch.
|
| experiment_id
| String ID of the experiment for the current run.
|
| lifecycle_stage
| One of the values in :py:class:`mlflow.entities.lifecycle_stage.LifecycleStage`
| describing the lifecycle stage of the run.
|
| run_id
| String containing run id.
|
| run_name
| String containing run name.
|
| start_time
| Start time of the run, in number of milliseconds since the UNIX epoch.
|
| status
| One of the values in :py:class:`mlflow.entities.RunStatus`
| describing the status of the run.
|
| user_id
| String ID of the user who initiated this run.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class RunInputs(mlflow.entities._mlflow_object._MlflowObject)
| RunInputs(dataset_inputs: list[mlflow.entities.dataset_input.DatasetInput], model_inputs: list[mlflow.entities.logged_model_input.LoggedModelInput] | None = None) -> None
|
| RunInputs object.
|
| Method resolution order:
| RunInputs
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other: mlflow.entities._mlflow_object._MlflowObject) -> bool
| Return self==value.
|
| __init__(self, dataset_inputs: list[mlflow.entities.dataset_input.DatasetInput], model_inputs: list[mlflow.entities.logged_model_input.LoggedModelInput] | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| to_dictionary(self) -> dict[str, typing.Any]
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| dataset_inputs
| Array of dataset inputs.
|
| model_inputs
| Array of model inputs.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class RunOutputs(mlflow.entities._mlflow_object._MlflowObject)
| RunOutputs(model_outputs: list[mlflow.entities.logged_model_output.LoggedModelOutput]) -> None
|
| RunOutputs object.
|
| Method resolution order:
| RunOutputs
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other: mlflow.entities._mlflow_object._MlflowObject) -> bool
| Return self==value.
|
| __init__(self, model_outputs: list[mlflow.entities.logged_model_output.LoggedModelOutput]) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| to_dictionary(self) -> dict[typing.Any, typing.Any]
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| model_outputs
| Array of model outputs.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class RunStatus(builtins.object)
| Enum for status of an :py:class:`mlflow.entities.Run`.
|
| Static methods defined here:
|
| all_status()
|
| from_string(status_str)
|
| is_terminated(status)
|
| to_string(status)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| FAILED = 4
|
| FINISHED = 3
|
| KILLED = 5
|
| RUNNING = 1
|
| SCHEDULED = 2
class RunTag(mlflow.entities._mlflow_object._MlflowObject)
| RunTag(key, value)
|
| Tag object associated with a run.
|
| Method resolution order:
| RunTag
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, key, value)
| Initialize self. See help(type(self)) for accurate signature.
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| key
| String name of the tag.
|
| value
| String value of the tag.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class ScorerVersion(mlflow.entities._mlflow_object._MlflowObject)
| ScorerVersion(experiment_id: str, scorer_name: str, scorer_version: int, serialized_scorer: str, creation_time: int, scorer_id: str | None = None)
|
| A versioned scorer entity that represents a specific version of a scorer within an MLflow
| experiment.
|
| Each ScorerVersion instance is uniquely identified by the combination of:
| - experiment_id: The experiment containing the scorer
| - scorer_name: The name of the scorer
| - scorer_version: The version number of the scorer
|
| The class provides access to both the metadata (name, version, creation time) and the actual
| scorer implementation through the serialized_scorer property, which deserializes the stored
| scorer data into a usable SerializedScorer object.
|
| Args:
| experiment_id (str): The ID of the experiment this scorer belongs to.
| scorer_name (str): The name identifier for the scorer.
| scorer_version (int): The version number of this scorer instance.
| serialized_scorer (str): JSON-serialized string containing the scorer's metadata and code.
| creation_time (int): Unix timestamp (in milliseconds) when this version was created.
| scorer_id (str, optional): The unique identifier for the scorer.
|
| Example:
| .. code-block:: python
|
| from mlflow.entities.scorer import ScorerVersion
|
| # Create a ScorerVersion instance
| scorer_version = ScorerVersion(
| experiment_id="123",
| scorer_name="accuracy_scorer",
| scorer_version=2,
| serialized_scorer='{"name": "accuracy_scorer", "call_source": "..."}',
| creation_time=1640995200000,
| )
|
| # Access scorer metadata
| print(f"Scorer: {scorer_version.scorer_name} v{scorer_version.scorer_version}")
| print(f"Created: {scorer_version.creation_time}")
|
| Method resolution order:
| ScorerVersion
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __init__(self, experiment_id: str, scorer_name: str, scorer_version: int, serialized_scorer: str, creation_time: int, scorer_id: str | None = None)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return a string representation of the ScorerVersion instance.
|
| Returns:
| str: A human-readable string showing the key identifying information
| of this scorer version (experiment_id, scorer_name, and scorer_version).
|
| serialized_scorer = <functools.cached_property object>
| The deserialized scorer object containing metadata and function code.
|
| This property automatically deserializes the stored JSON string into a
| SerializedScorer object that contains all the information needed to
| reconstruct and execute the scorer function.
|
| The result is cached to avoid repeated deserialization
| when the same ScorerVersion instance is accessed multiple times.
|
| Returns:
| SerializedScorer: A `SerializedScorer` object with metadata, function code,
| and configuration information.
|
| Note:
| The `SerializedScorer` object construction is lazy,
| it only happens when this property is first accessed.
|
| to_proto(self)
| Convert this ScorerVersion instance to a protobuf message.
|
| This method serializes the ScorerVersion data into a protobuf format
| for transmission over the network or storage in binary format. It's
| primarily used internally by MLflow's tracking infrastructure.
|
| Returns:
| ProtoScorer: A protobuf message containing the serialized scorer version data.
|
| Note:
| This method is primarily used internally by MLflow's tracking infrastructure
| and should not typically be called directly by users.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
| Create a ScorerVersion instance from a protobuf message.
|
| This class method is used internally by MLflow to reconstruct ScorerVersion
| objects from serialized protobuf data, typically when retrieving scorers
| from remote tracking servers or deserializing stored data.
|
| Args:
| proto: A protobuf message containing scorer version data.
|
| Returns:
| ScorerVersion: A new ScorerVersion instance populated with data from the protobuf.
|
| Note:
| This method is primarily used internally by MLflow's tracking infrastructure
| and should not typically be called directly by users.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| creation_time
| The timestamp when this scorer version was created.
|
| Returns:
| int: Unix timestamp in milliseconds representing when this specific
| version of the scorer was registered in MLflow.
|
| experiment_id
| The ID of the experiment this scorer belongs to.
|
| Returns:
| str: The id of the experiment that this scorer version belongs to.
|
| scorer_id
| The unique identifier for the scorer.
|
| Returns:
| str: The unique identifier (UUID) for the scorer, or None if not available.
|
| scorer_name
| The name identifier for the scorer.
|
| Returns:
| str: The human-readable name used to identify and reference this scorer.
|
| scorer_version
| The version number of this scorer instance.
|
| Returns:
| int: The sequential version number, starting from 1. Higher versions represent
| newer saved scorers with the same name.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class Session(builtins.object)
| Session(traces: 'list[Trace]')
|
| A session object representing a group of traces that share the same session ID.
|
| Sessions typically represent multi-turn conversations or related interactions.
| This class provides convenient access to the session ID and allows iteration
| over the traces in the session.
|
| Args:
| traces: A list of Trace objects that belong to this session.
|
| Methods defined here:
|
| __getitem__(self, index: 'int') -> 'Trace'
|
| __init__(self, traces: 'list[Trace]')
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self) -> 'Iterator[Trace]'
|
| __len__(self) -> 'int'
|
| __repr__(self) -> 'str'
| Return repr(self).
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| id
|
| traces
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class SourceType(builtins.object)
| Enum for originating source of a :py:class:`mlflow.entities.Run`.
|
| Static methods defined here:
|
| from_string(status_str)
|
| to_string(status)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| JOB = 2
|
| LOCAL = 4
|
| NOTEBOOK = 1
|
| PROJECT = 3
|
| SOURCETYPE_TO_STRING = {1: 'NOTEBOOK', 2: 'JOB', 3: 'PROJECT', 4: 'LOC...
|
| UNKNOWN = 5
class Span(builtins.object)
| Span(otel_span: opentelemetry.sdk.trace.ReadableSpan)
|
| A span object. A span represents a unit of work or operation and is the building
| block of Traces.
|
| This Span class represents immutable span data that is already finished and persisted.
| The "live" span that is being created and updated during the application runtime is
| represented by the :py:class:`LiveSpan <mlflow.entities.LiveSpan>` subclass.
|
| Methods defined here:
|
| __init__(self, otel_span: opentelemetry.sdk.trace.ReadableSpan)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| get_attribute(self, key: str) -> typing.Any | None
| Get a single attribute value from the span.
|
| Args:
| key: The key of the attribute to get.
|
| Returns:
| The value of the attribute if it exists, otherwise None.
|
| to_dict(self) -> dict[str, typing.Any]
|
| to_otel_proto(self) -> opentelemetry.proto.trace.v1.trace_pb2.Span
| Convert to OpenTelemetry protobuf span format for OTLP export.
| This is an internal method used by the REST store for logging spans.
|
| Returns:
| An OpenTelemetry protobuf Span message.
|
| trace_id = <functools.cached_property object>
| The trace ID of the span, a unique identifier for the trace it belongs to.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dict(data: dict[str, typing.Any]) -> 'Span'
| Create a Span object from the given dictionary.
|
| from_dict_v2(data: dict[str, typing.Any]) -> 'Span'
| Create a Span object from the given dictionary in v2 schema.
|
| from_otel_proto(otel_proto_span: opentelemetry.proto.trace.v1.trace_pb2.Span, location_id: str | None = None, *, preserve_request_id: bool = False, resource: opentelemetry.proto.resource.v1.resource_pb2.Resource | None = None) -> 'Span'
| Create a Span from an OpenTelemetry protobuf span.
|
| This is an internal method used for receiving spans via OTel protocol. By default,
| MLflow derives the canonical ``mlflow.traceRequestId`` from the OTLP trace ID so server
| ingest does not trust a client-sent request ID. Set ``preserve_request_id=True`` only for
| trusted internal round-trip flows, such as archived trace payload deserialization, where
| the stored MLflow request ID must be preserved exactly if present.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| attributes
| Get all attributes of the span.
|
| Returns:
| A dictionary of all attributes of the span.
|
| end_time_ns
| The end time of the span in nanosecond.
|
| events
| Get all events of the span.
|
| Returns:
| A list of all events of the span.
|
| inputs
| The input values of the span.
|
| links
| Get all links of the span.
|
| Returns:
| A list of all links of the span.
|
| llm_cost
| The cost information for the span in USD.
|
| Returns a dictionary with keys:
| - input_cost: Cost of input tokens
| - output_cost: Cost of output tokens
| - total_cost: Total cost (input + output)
|
| Returns None if cost information is not available.
|
| log_level
| The severity level of the span, or ``None`` if it was not classified.
|
| Set on a :py:class:`LiveSpan <mlflow.entities.LiveSpan>` via
| :py:meth:`set_log_level <mlflow.entities.LiveSpan.set_log_level>`,
| the ``log_level`` argument of :py:func:`mlflow.start_span`,
| :py:func:`mlflow.start_span_no_context`, or :py:func:`mlflow.trace`,
| or by an autologging integration on the user's behalf.
|
| model_name
| The model name used in the span.
|
| name
| The name of the span.
|
| outputs
| The output values of the span.
|
| parent_id
| The span ID of the parent span.
|
| request_id
| Deprecated. Use `trace_id` instead.
|
| span_id
| The ID of the span. This is only unique within a trace.
|
| span_type
| The type of the span.
|
| start_time_ns
| The start time of the span in nanosecond.
|
| status
| The status of the span.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class SpanEvent(mlflow.entities._mlflow_object._MlflowObject)
| SpanEvent(name: str, timestamp: int = <factory>, attributes: dict[str, str | bool | int | float | collections.abc.Sequence[str] | collections.abc.Sequence[bool] | collections.abc.Sequence[int] | collections.abc.Sequence[float]] = <factory>) -> None
|
| An event that records a specific occurrences or moments in time
| during a span, such as an exception being thrown. Compatible with OpenTelemetry.
|
| Args:
| name: Name of the event.
| timestamp: The exact time the event occurred, measured in nanoseconds.
| If not provided, the current time will be used.
| attributes: A collection of key-value pairs representing detailed
| attributes of the event, such as the exception stack trace.
| Attributes value must be one of ``[str, int, float, bool, bytes]``
| or a sequence of these types.
|
| Method resolution order:
| SpanEvent
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, name: str, timestamp: int = <factory>, attributes: dict[str, str | bool | int | float | collections.abc.Sequence[str] | collections.abc.Sequence[bool] | collections.abc.Sequence[int] | collections.abc.Sequence[float]] = <factory>) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| json(self)
|
| to_otel_proto(self)
| Convert to OpenTelemetry protobuf event format for OTLP export.
| This is an internal method used for logging spans via OTel protocol.
|
| Returns:
| An OpenTelemetry protobuf Span.Event message.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_exception(exception: Exception)
| Create a span event from an exception.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'attributes': dict[str, str | bool | int | float | ...
|
| __dataclass_fields__ = {'attributes': Field(name='attributes',type=dic...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('name', 'timestamp', 'attributes')
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class SpanLogLevel(enum.IntEnum)
| SpanLogLevel(*values)
|
| Log level (severity) for an MLflow trace span.
|
| The public tracing API accepts a :class:`SpanLogLevel` member or its
| string name (e.g. ``"INFO"``).
|
| Method resolution order:
| SpanLogLevel
| enum.IntEnum
| builtins.int
| enum.ReprEnum
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec, /) from builtins.int
| Convert to a string according to format_spec.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| CRITICAL = <SpanLogLevel.CRITICAL: 50>
|
| DEBUG = <SpanLogLevel.DEBUG: 10>
|
| ERROR = <SpanLogLevel.ERROR: 40>
|
| INFO = <SpanLogLevel.INFO: 20>
|
| WARNING = <SpanLogLevel.WARNING: 30>
|
| ----------------------------------------------------------------------
| Methods inherited from enum.IntEnum:
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__ = __repr__(self, /) from builtins.int
| Return repr(self).
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.int:
|
| __abs__(self, /)
| abs(self)
|
| __add__(self, value, /)
| Return self+value.
|
| __and__(self, value, /)
| Return self&value.
|
| __bool__(self, /)
| True if self else False
|
| __ceil__(...)
| Ceiling of an Integral returns itself.
|
| __divmod__(self, value, /)
| Return divmod(self, value).
|
| __eq__(self, value, /)
| Return self==value.
|
| __float__(self, /)
| float(self)
|
| __floor__(...)
| Flooring an Integral returns itself.
|
| __floordiv__(self, value, /)
| Return self//value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __index__(self, /)
| Return self converted to an integer, if self is suitable for use as an index into a list.
|
| __int__(self, /)
| int(self)
|
| __invert__(self, /)
| ~self
|
| __le__(self, value, /)
| Return self<=value.
|
| __lshift__(self, value, /)
| Return self<<value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __neg__(self, /)
| -self
|
| __or__(self, value, /)
| Return self|value.
|
| __pos__(self, /)
| +self
|
| __pow__(self, value, mod=None, /)
| Return pow(self, value, mod).
|
| __radd__(self, value, /)
| Return value+self.
|
| __rand__(self, value, /)
| Return value&self.
|
| __rdivmod__(self, value, /)
| Return divmod(value, self).
|
| __rfloordiv__(self, value, /)
| Return value//self.
|
| __rlshift__(self, value, /)
| Return value<<self.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __ror__(self, value, /)
| Return value|self.
|
| __round__(...)
| Rounding an Integral returns itself.
|
| Rounding with an ndigits argument also returns an integer.
|
| __rpow__(self, value, mod=None, /)
| Return pow(value, self, mod).
|
| __rrshift__(self, value, /)
| Return value>>self.
|
| __rshift__(self, value, /)
| Return self>>value.
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rtruediv__(self, value, /)
| Return value/self.
|
| __rxor__(self, value, /)
| Return value^self.
|
| __sizeof__(self, /)
| Returns size in memory, in bytes.
|
| __sub__(self, value, /)
| Return self-value.
|
| __truediv__(self, value, /)
| Return self/value.
|
| __trunc__(...)
| Truncating an Integral returns itself.
|
| __xor__(self, value, /)
| Return self^value.
|
| as_integer_ratio(self, /)
| Return a pair of integers, whose ratio is equal to the original int.
|
| The ratio is in lowest terms and has a positive denominator.
|
| >>> (10).as_integer_ratio()
| (10, 1)
| >>> (-10).as_integer_ratio()
| (-10, 1)
| >>> (0).as_integer_ratio()
| (0, 1)
|
| bit_count(self, /)
| Number of ones in the binary representation of the absolute value of self.
|
| Also known as the population count.
|
| >>> bin(13)
| '0b1101'
| >>> (13).bit_count()
| 3
|
| bit_length(self, /)
| Number of bits necessary to represent self in binary.
|
| >>> bin(37)
| '0b100101'
| >>> (37).bit_length()
| 6
|
| conjugate(...)
| Returns self, the complex conjugate of any int.
|
| is_integer(self, /)
| Returns True. Exists for duck type compatibility with float.is_integer.
|
| to_bytes(self, /, length=1, byteorder='big', *, signed=False)
| Return an array of bytes representing an integer.
|
| length
| Length of bytes object to use. An OverflowError is raised if the
| integer is not representable with the given number of bytes. Default
| is length 1.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Determines whether two's complement is used to represent the integer.
| If signed is False and a negative integer is given, an OverflowError
| is raised.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.int:
|
| from_bytes(bytes, byteorder='big', *, signed=False)
| Return the integer represented by the given array of bytes.
|
| bytes
| Holds the array of bytes to convert. The argument must either
| support the buffer protocol or be an iterable object producing bytes.
| Bytes and bytearray are examples of built-in objects that support the
| buffer protocol.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Indicates whether two's complement is used to represent the integer.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.int:
|
| denominator
| the denominator of a rational number in lowest terms
|
| imag
| the imaginary part of a complex number
|
| numerator
| the numerator of a rational number in lowest terms
|
| real
| the real part of a complex number
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Static methods inherited from enum.EnumType:
|
| __contains__(value)
| Return True if `value` is in `cls`.
|
| `value` is in `cls` if:
| 1) `value` is a member of `cls`, or
| 2) `value` is the value of one of the `cls`'s members.
|
| __getitem__(name)
| Return the member matching `name`.
|
| __iter__()
| Return members in definition order.
|
| __len__()
| Return the number of members (no aliases)
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class SpanStatus(builtins.object)
| SpanStatus(status_code: 'SpanStatusCode', description: 'str' = '') -> None
|
| Status of the span or the trace.
|
| Args:
| status_code: The status code of the span or the trace. This must be one of the
| values of the :py:class:`mlflow.entities.SpanStatusCode` enum or a string
| representation of it like "OK", "ERROR".
| description: Description of the status. This should be only set when the status
| is ERROR, otherwise it will be ignored.
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, status_code: 'SpanStatusCode', description: 'str' = '') -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __post_init__(self)
| If user provides a string status code, validate it and convert to
| the corresponding enum value.
|
| __repr__(self)
| Return repr(self).
|
| to_otel_proto_status(self)
| Convert to OpenTelemetry protobuf Status for OTLP export.
|
| :meta private:
|
| to_otel_status(self) -> 'trace_api.Status'
| Convert :py:class:`mlflow.entities.SpanStatus` object to OpenTelemetry status object.
|
| :meta private:
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_otel_proto_status(otel_proto_status) -> 'SpanStatus'
| Create a SpanStatus from an OpenTelemetry protobuf Status.
|
| :meta private:
|
| from_otel_status(otel_status: 'trace_api.Status') -> 'SpanStatus'
| Convert OpenTelemetry status object to our status object.
|
| :meta private:
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'description': 'str', 'status_code': 'SpanStatusCod...
|
| __dataclass_fields__ = {'description': Field(name='description',type='...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('status_code', 'description')
|
| description = ''
class SpanStatusCode(builtins.str, enum.Enum)
| SpanStatusCode(*values)
|
| Enum for status code of a span
|
| Method resolution order:
| SpanStatusCode
| builtins.str
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec) from enum.Enum
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__(self) from enum.Enum
| Return str(self).
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| ERROR = <SpanStatusCode.ERROR: 'ERROR'>
|
| OK = <SpanStatusCode.OK: 'OK'>
|
| UNSET = <SpanStatusCode.UNSET: 'UNSET'>
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.str:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(...)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __sizeof__(self, /)
| Return the size of the string in memory, in bytes.
|
| capitalize(self, /)
| Return a capitalized version of the string.
|
| More specifically, make the first character have upper case and the rest lower
| case.
|
| casefold(self, /)
| Return a version of the string suitable for caseless comparisons.
|
| center(self, width, fillchar=' ', /)
| Return a centered string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| count(...)
| S.count(sub[, start[, end]]) -> int
|
| Return the number of non-overlapping occurrences of substring sub in
| string S[start:end]. Optional arguments start and end are
| interpreted as in slice notation.
|
| encode(self, /, encoding='utf-8', errors='strict')
| Encode the string using the codec registered for encoding.
|
| encoding
| The encoding in which to encode the string.
| errors
| The error handling scheme to use for encoding errors.
| The default is 'strict' meaning that encoding errors raise a
| UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
| 'xmlcharrefreplace' as well as any other name registered with
| codecs.register_error that can handle UnicodeEncodeErrors.
|
| endswith(...)
| S.endswith(suffix[, start[, end]]) -> bool
|
| Return True if S ends with the specified suffix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| suffix can also be a tuple of strings to try.
|
| expandtabs(self, /, tabsize=8)
| Return a copy where all tab characters are expanded using spaces.
|
| If tabsize is not given, a tab size of 8 characters is assumed.
|
| find(...)
| S.find(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| format(...)
| S.format(*args, **kwargs) -> str
|
| Return a formatted version of S, using substitutions from args and kwargs.
| The substitutions are identified by braces ('{' and '}').
|
| format_map(...)
| S.format_map(mapping) -> str
|
| Return a formatted version of S, using substitutions from mapping.
| The substitutions are identified by braces ('{' and '}').
|
| index(...)
| S.index(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| isalnum(self, /)
| Return True if the string is an alpha-numeric string, False otherwise.
|
| A string is alpha-numeric if all characters in the string are alpha-numeric and
| there is at least one character in the string.
|
| isalpha(self, /)
| Return True if the string is an alphabetic string, False otherwise.
|
| A string is alphabetic if all characters in the string are alphabetic and there
| is at least one character in the string.
|
| isascii(self, /)
| Return True if all characters in the string are ASCII, False otherwise.
|
| ASCII characters have code points in the range U+0000-U+007F.
| Empty string is ASCII too.
|
| isdecimal(self, /)
| Return True if the string is a decimal string, False otherwise.
|
| A string is a decimal string if all characters in the string are decimal and
| there is at least one character in the string.
|
| isdigit(self, /)
| Return True if the string is a digit string, False otherwise.
|
| A string is a digit string if all characters in the string are digits and there
| is at least one character in the string.
|
| isidentifier(self, /)
| Return True if the string is a valid Python identifier, False otherwise.
|
| Call keyword.iskeyword(s) to test whether string s is a reserved identifier,
| such as "def" or "class".
|
| islower(self, /)
| Return True if the string is a lowercase string, False otherwise.
|
| A string is lowercase if all cased characters in the string are lowercase and
| there is at least one cased character in the string.
|
| isnumeric(self, /)
| Return True if the string is a numeric string, False otherwise.
|
| A string is numeric if all characters in the string are numeric and there is at
| least one character in the string.
|
| isprintable(self, /)
| Return True if the string is printable, False otherwise.
|
| A string is printable if all of its characters are considered printable in
| repr() or if it is empty.
|
| isspace(self, /)
| Return True if the string is a whitespace string, False otherwise.
|
| A string is whitespace if all characters in the string are whitespace and there
| is at least one character in the string.
|
| istitle(self, /)
| Return True if the string is a title-cased string, False otherwise.
|
| In a title-cased string, upper- and title-case characters may only
| follow uncased characters and lowercase characters only cased ones.
|
| isupper(self, /)
| Return True if the string is an uppercase string, False otherwise.
|
| A string is uppercase if all cased characters in the string are uppercase and
| there is at least one cased character in the string.
|
| join(self, iterable, /)
| Concatenate any number of strings.
|
| The string whose method is called is inserted in between each given string.
| The result is returned as a new string.
|
| Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
|
| ljust(self, width, fillchar=' ', /)
| Return a left-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| lower(self, /)
| Return a copy of the string converted to lowercase.
|
| lstrip(self, chars=None, /)
| Return a copy of the string with leading whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| partition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string. If the separator is found,
| returns a 3-tuple containing the part before the separator, the separator
| itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing the original string
| and two empty strings.
|
| removeprefix(self, prefix, /)
| Return a str with the given prefix string removed if present.
|
| If the string starts with the prefix string, return string[len(prefix):].
| Otherwise, return a copy of the original string.
|
| removesuffix(self, suffix, /)
| Return a str with the given suffix string removed if present.
|
| If the string ends with the suffix string and that suffix is not empty,
| return string[:-len(suffix)]. Otherwise, return a copy of the original
| string.
|
| replace(self, old, new, count=-1, /)
| Return a copy with all occurrences of substring old replaced by new.
|
| count
| Maximum number of occurrences to replace.
| -1 (the default value) means replace all occurrences.
|
| If the optional argument count is given, only the first count occurrences are
| replaced.
|
| rfind(...)
| S.rfind(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| rindex(...)
| S.rindex(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| rjust(self, width, fillchar=' ', /)
| Return a right-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| rpartition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string, starting at the end. If
| the separator is found, returns a 3-tuple containing the part before the
| separator, the separator itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing two empty strings
| and the original string.
|
| rsplit(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the end of the string and works to the front.
|
| rstrip(self, chars=None, /)
| Return a copy of the string with trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| split(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the front of the string and works to the end.
|
| Note, str.split() is mainly useful for data that has been intentionally
| delimited. With natural text that includes punctuation, consider using
| the regular expression module.
|
| splitlines(self, /, keepends=False)
| Return a list of the lines in the string, breaking at line boundaries.
|
| Line breaks are not included in the resulting list unless keepends is given and
| true.
|
| startswith(...)
| S.startswith(prefix[, start[, end]]) -> bool
|
| Return True if S starts with the specified prefix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| prefix can also be a tuple of strings to try.
|
| strip(self, chars=None, /)
| Return a copy of the string with leading and trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| swapcase(self, /)
| Convert uppercase characters to lowercase and lowercase characters to uppercase.
|
| title(self, /)
| Return a version of the string where each word is titlecased.
|
| More specifically, words start with uppercased characters and all remaining
| cased characters have lower case.
|
| translate(self, table, /)
| Replace each character in the string using the given translation table.
|
| table
| Translation table, which must be a mapping of Unicode ordinals to
| Unicode ordinals, strings, or None.
|
| The table must implement lookup/indexing via __getitem__, for instance a
| dictionary or list. If this operation raises LookupError, the character is
| left untouched. Characters mapped to None are deleted.
|
| upper(self, /)
| Return a copy of the string converted to uppercase.
|
| zfill(self, width, /)
| Pad a numeric string with zeros on the left, to fill a field of the given width.
|
| The string is never truncated.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.str:
|
| maketrans(...)
| Return a translation table usable for str.translate().
|
| If there is only one argument, it must be a dictionary mapping Unicode
| ordinals (integers) or characters to Unicode ordinals, strings or None.
| Character keys will be then converted to ordinals.
| If there are two arguments, they must be strings of equal length, and
| in the resulting dictionary, each character in x will be mapped to the
| character at the same position in y. If there is a third argument, it
| must be a string, whose characters will be mapped to None in the result.
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class SpanType(builtins.object)
| Predefined set of span types.
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| AGENT = 'AGENT'
|
| CHAIN = 'CHAIN'
|
| CHAT_MODEL = 'CHAT_MODEL'
|
| EMBEDDING = 'EMBEDDING'
|
| EVALUATOR = 'EVALUATOR'
|
| GUARDRAIL = 'GUARDRAIL'
|
| LLM = 'LLM'
|
| MEMORY = 'MEMORY'
|
| PARSER = 'PARSER'
|
| RERANKER = 'RERANKER'
|
| RETRIEVER = 'RETRIEVER'
|
| TASK = 'TASK'
|
| TOOL = 'TOOL'
|
| UNKNOWN = 'UNKNOWN'
|
| WORKFLOW = 'WORKFLOW'
class Trace(mlflow.entities._mlflow_object._MlflowObject)
| Trace(info: 'TraceInfo', data: 'TraceData') -> None
|
| A trace object.
|
| Args:
| info: A lightweight object that contains the metadata of a trace.
| data: A container object that holds the spans data of a trace.
|
| Method resolution order:
| Trace
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, info: 'TraceInfo', data: 'TraceData') -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __post_init__(self)
|
| __repr__(self) -> 'str'
| Return repr(self).
|
| search_assessments(self, name: 'str | None' = None, *, span_id: 'str | None' = None, all: 'bool' = False, type: "Literal['expectation', 'feedback'] | None" = None) -> "list['Assessment']"
| Get assessments for a given name / span ID. By default, this only returns assessments
| that are valid (i.e. have not been overridden by another assessment). To return all
| assessments, specify `all=True`.
|
| Args:
| name: The name of the assessment to get. If not provided, this will match
| all assessment names.
| span_id: The span ID to get assessments for.
| If not provided, this will match all spans.
| all: If True, return all assessments regardless of validity.
| type: The type of assessment to get (one of "feedback" or "expectation").
| If not provided, this will match all assessment types.
|
| Returns:
| A list of assessments that meet the given conditions.
|
| search_spans(self, span_type: 'SpanType | None' = None, name: 'str | re.Pattern | None' = None, span_id: 'str | None' = None) -> 'list[Span]'
| Search for spans that match the given criteria within the trace.
|
| Args:
| span_type: The type of the span to search for.
| name: The name of the span to search for. This can be a string or a regular expression.
| span_id: The ID of the span to search for.
|
| Returns:
| A list of spans that match the given criteria.
| If there is no match, an empty list is returned.
|
| .. code-block:: python
|
| import mlflow
| import re
| from mlflow.entities import SpanType
|
|
| @mlflow.trace(span_type=SpanType.CHAIN)
| def run(x: int) -> int:
| x = add_one(x)
| x = add_two(x)
| x = multiply_by_two(x)
| return x
|
|
| @mlflow.trace(span_type=SpanType.TOOL)
| def add_one(x: int) -> int:
| return x + 1
|
|
| @mlflow.trace(span_type=SpanType.TOOL)
| def add_two(x: int) -> int:
| return x + 2
|
|
| @mlflow.trace(span_type=SpanType.TOOL)
| def multiply_by_two(x: int) -> int:
| return x * 2
|
|
| # Run the function and get the trace
| y = run(2)
| trace_id = mlflow.get_last_active_trace_id()
| trace = mlflow.get_trace(trace_id)
|
| # 1. Search spans by name (exact match)
| spans = trace.search_spans(name="add_one")
| print(spans)
| # Output: [Span(name='add_one', ...)]
|
| # 2. Search spans by name (regular expression)
| pattern = re.compile(r"add.*")
| spans = trace.search_spans(name=pattern)
| print(spans)
| # Output: [Span(name='add_one', ...), Span(name='add_two', ...)]
|
| # 3. Search spans by type
| spans = trace.search_spans(span_type=SpanType.LLM)
| print(spans)
| # Output: [Span(name='run', ...)]
|
| # 4. Search spans by name and type
| spans = trace.search_spans(name="add_one", span_type=SpanType.TOOL)
| print(spans)
| # Output: [Span(name='add_one', ...)]
|
| to_dict(self) -> 'dict[str, Any]'
|
| to_json(self, pretty=False) -> 'str'
|
| to_pandas_dataframe_row(self) -> 'dict[str, Any]'
|
| to_proto(self)
| Convert into a proto object to sent to the MLflow backend.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dict(trace_dict: 'dict[str, Any]') -> 'Trace'
|
| from_json(trace_json: 'str') -> 'Trace'
|
| from_proto(proto: 'ProtoTrace') -> "'Trace'"
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| pandas_dataframe_columns() -> 'list[str]'
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'data': 'TraceData', 'info': 'TraceInfo'}
|
| __dataclass_fields__ = {'data': Field(name='data',type='TraceData',def...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('info', 'data')
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class TraceArchivalConfig(builtins.object)
| TraceArchivalConfig(location: 'str | None' = None, retention: 'str | None' = None) -> None
|
| Python-facing configuration for workspace trace archival.
|
| Use ``location`` for the archival storage URI/root and ``retention`` for the retention
| duration formatted as ``<int><unit>`` such as ``30d`` or ``12h``.
|
| ``None`` leaves a field unset. For update-style APIs, use an empty string to clear an
| existing value while leaving a field as ``None`` keeps the current value unchanged.
|
| Methods defined here:
|
| __delattr__(self, name)
| Implement delattr(self, name).
|
| __eq__(self, other)
| Return self==value.
|
| __getstate__ = _dataclass_getstate(self) from dataclasses
| # _dataclass_getstate and _dataclass_setstate are needed for pickling frozen
| # classes with slots. These could be slightly more performant if we generated
| # the code instead of iterating over fields. But that can be a project for
| # another day, if performance becomes an issue.
|
| __hash__(self)
| Return hash(self).
|
| __init__(self, location: 'str | None' = None, retention: 'str | None' = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| __setattr__(self, name, value)
| Implement setattr(self, name, value).
|
| __setstate__ = _dataclass_setstate(self, state) from dataclasses
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| location
|
| retention
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'location': 'str | None', 'retention': 'str | None'...
|
| __dataclass_fields__ = {'location': Field(name='location',type='str | ...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __match_args__ = ('location', 'retention')
class TraceData(builtins.object)
| TraceData(spans: list[mlflow.entities.span.Span] | None = None, **kwargs)
|
| A container object that holds the spans data of a trace.
|
| Args:
| spans: List of spans that are part of the trace.
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, spans: list[mlflow.entities.span.Span] | None = None, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| to_dict(self) -> dict[str, typing.Any]
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dict(d)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| intermediate_outputs
| .. Warning:: ``mlflow.entities.trace_data.TraceData.intermediate_outputs`` is deprecated since 3.6.0. This method will be removed in a future release. Use ``trace.search_spans(name=...)`` instead.
|
| .. deprecated:: 3.6.0
| Use `trace.search_spans(name=...)` to search for spans and get the outputs.
|
| Returns intermediate outputs produced by the model or agent while handling the request.
| There are mainly two flows to return intermediate outputs:
| 1. When a trace is generate by the `mlflow.log_trace` API,
| return `intermediate_outputs` attribute of the span.
| 2. When a trace is created normally with a tree of spans,
| aggregate the outputs of non-root spans.
|
| request
|
| response
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'spans': list[mlflow.entities.span.Span]}
|
| __dataclass_fields__ = {'spans': Field(name='spans',type=list[mlflow.e...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('spans',)
class TraceInfo(mlflow.entities._mlflow_object._MlflowObject)
| TraceInfo(trace_id: str, trace_location: mlflow.entities.trace_location.TraceLocation, request_time: int, state: mlflow.entities.trace_state.TraceState, request_preview: str | None = None, response_preview: str | None = None, client_request_id: str | None = None, execution_duration: int | None = None, trace_metadata: dict[str, str] = <factory>, tags: dict[str, str] = <factory>, assessments: list[mlflow.entities.assessment.Assessment] = <factory>) -> None
|
| Metadata about a trace, such as its ID, location, timestamp, etc.
|
| Args:
| trace_id: The primary identifier for the trace.
| trace_location: The location where the trace is stored, represented as
| a :py:class:`~mlflow.entities.TraceLocation` object. MLflow currently
| support MLflow Experiment or Databricks Inference Table as a trace location.
| request_time: Start time of the trace, in milliseconds.
| state: State of the trace, represented as a :py:class:`~mlflow.entities.TraceState`
| enum. Can be one of [`OK`, `ERROR`, `IN_PROGRESS`, `STATE_UNSPECIFIED`].
| request_preview: Request to the model/agent, equivalent to the input of the root,
| span but JSON-encoded and can be truncated.
| response_preview: Response from the model/agent, equivalent to the output of the
| root span but JSON-encoded and can be truncated.
| client_request_id: Client supplied request ID associated with the trace. This
| could be used to identify the trace/request from an external system that
| produced the trace, e.g., a session ID in a web application.
| execution_duration: Duration of the trace, in milliseconds.
| trace_metadata: Key-value pairs associated with the trace. They are designed
| for immutable values like run ID associated with the trace.
| tags: Tags associated with the trace. They are designed for mutable values,
| that can be updated after the trace is created via MLflow UI or API.
| assessments: List of assessments associated with the trace.
|
| Method resolution order:
| TraceInfo
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, trace_id: str, trace_location: mlflow.entities.trace_location.TraceLocation, request_time: int, state: mlflow.entities.trace_state.TraceState, request_preview: str | None = None, response_preview: str | None = None, client_request_id: str | None = None, execution_duration: int | None = None, trace_metadata: dict[str, str] = <factory>, tags: dict[str, str] = <factory>, assessments: list[mlflow.entities.assessment.Assessment] = <factory>) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| to_dict(self) -> dict[str, typing.Any]
| Convert the TraceInfoV3 object to a dictionary.
|
| to_proto(self) -> service_pb2.TraceInfoV3 | databricks_tracing_pb2.TraceInfo
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dict(d: dict[str, typing.Any]) -> 'TraceInfo'
| Create a TraceInfoV3 object from a dictionary.
|
| from_proto(proto) -> 'TraceInfo'
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| cost
| Returns the aggregated cost for the trace in USD.
|
| Returns:
| A dictionary containing the aggregated LLM cost for the trace.
| - "input_cost": The total cost for input tokens.
| - "output_cost": The total cost for output tokens.
| - "total_cost": Sum of input and output costs.
|
| .. note::
|
| The cost tracking is calculated based on token usage and model pricing
| from LiteLLM. Cost tracking is not supported for all LLM providers.
| Refer to the MLflow Tracing documentation for which providers
| support cost tracking.
|
| request_id
| Deprecated. Use `trace_id` instead.
|
| request_metadata
| Deprecated. Use `trace_metadata` instead.
|
| token_usage
| Returns the aggregated token usage for the trace.
|
| Returns:
| A dictionary containing the aggregated LLM token usage for the trace.
| - "input_tokens": The total number of input tokens.
| - "output_tokens": The total number of output tokens.
| - "total_tokens": Sum of input and output tokens.
|
| .. note::
|
| The token usage tracking is not supported for all LLM providers.
| Refer to the MLflow Tracing documentation for which providers
| support token usage tracking.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| execution_time_ms
|
| experiment_id
| An MLflow experiment ID associated with the trace, if the trace is stored
| in MLflow tracking server. Otherwise, None.
|
| status
| Deprecated. Use `state` instead.
|
| timestamp_ms
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'assessments': list[mlflow.entities.assessment.Asse...
|
| __dataclass_fields__ = {'assessments': Field(name='assessments',type=l...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('trace_id', 'trace_location', 'request_time', 'state...
|
| client_request_id = None
|
| execution_duration = None
|
| request_preview = None
|
| response_preview = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class TraceLocation(mlflow.entities._mlflow_object._MlflowObject)
| TraceLocation(type: mlflow.entities.trace_location.TraceLocationType, mlflow_experiment: mlflow.entities.trace_location.MlflowExperimentLocation | None = None, inference_table: mlflow.entities.trace_location.InferenceTableLocation | None = None, uc_schema: mlflow.entities.trace_location.UCSchemaLocation | None = None, uc_table_prefix: mlflow.entities.trace_location.UnityCatalog | None = None) -> None
|
| Represents the location where the trace is stored.
|
| Currently, MLflow supports two types of trace locations:
|
| - MLflow experiment: The trace is stored in an MLflow experiment.
| - Inference table: The trace is stored in a Databricks inference table.
|
| Args:
| type: The type of the trace location, should be one of the
| :py:class:`TraceLocationType` enum values.
| mlflow_experiment: The MLflow experiment location. Set this when the
| location type is MLflow experiment.
| inference_table: The inference table location. Set this when the
| location type is Databricks Inference table.
|
| Method resolution order:
| TraceLocation
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, type: mlflow.entities.trace_location.TraceLocationType, mlflow_experiment: mlflow.entities.trace_location.MlflowExperimentLocation | None = None, inference_table: mlflow.entities.trace_location.InferenceTableLocation | None = None, uc_schema: mlflow.entities.trace_location.UCSchemaLocation | None = None, uc_table_prefix: mlflow.entities.trace_location.UnityCatalog | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __post_init__(self) -> None
|
| __repr__(self)
| Return repr(self).
|
| to_dict(self) -> dict[str, typing.Any]
|
| to_proto(self) -> service_pb2.TraceLocation
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_databricks_uc_schema(catalog_name: str, schema_name: str) -> 'TraceLocation'
|
| from_databricks_uc_table_prefix(catalog_name: str, schema_name: str, table_prefix: str) -> 'TraceLocation'
|
| from_dict(d: dict[str, typing.Any]) -> 'TraceLocation'
|
| from_experiment_id(experiment_id: str) -> 'TraceLocation'
|
| from_proto(proto) -> 'TraceLocation'
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'inference_table': mlflow.entities.trace_location.I...
|
| __dataclass_fields__ = {'inference_table': Field(name='inference_table...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('type', 'mlflow_experiment', 'inference_table', 'uc_...
|
| inference_table = None
|
| mlflow_experiment = None
|
| uc_schema = None
|
| uc_table_prefix = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class TraceLocationType(builtins.str, enum.Enum)
| TraceLocationType(*values)
|
| Method resolution order:
| TraceLocationType
| builtins.str
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec) from enum.Enum
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__(self) from enum.Enum
| Return str(self).
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| INFERENCE_TABLE = <TraceLocationType.INFERENCE_TABLE: 'INFERENCE_TABLE...
|
| MLFLOW_EXPERIMENT = <TraceLocationType.MLFLOW_EXPERIMENT: 'MLFLOW_EXPE...
|
| TRACE_LOCATION_TYPE_UNSPECIFIED = <TraceLocationType.TRACE_LOCATION_TY...
|
| UC_SCHEMA = <TraceLocationType.UC_SCHEMA: 'UC_SCHEMA'>
|
| UC_TABLE_PREFIX = <TraceLocationType.UC_TABLE_PREFIX: 'UC_TABLE_PREFIX...
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.str:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(...)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __sizeof__(self, /)
| Return the size of the string in memory, in bytes.
|
| capitalize(self, /)
| Return a capitalized version of the string.
|
| More specifically, make the first character have upper case and the rest lower
| case.
|
| casefold(self, /)
| Return a version of the string suitable for caseless comparisons.
|
| center(self, width, fillchar=' ', /)
| Return a centered string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| count(...)
| S.count(sub[, start[, end]]) -> int
|
| Return the number of non-overlapping occurrences of substring sub in
| string S[start:end]. Optional arguments start and end are
| interpreted as in slice notation.
|
| encode(self, /, encoding='utf-8', errors='strict')
| Encode the string using the codec registered for encoding.
|
| encoding
| The encoding in which to encode the string.
| errors
| The error handling scheme to use for encoding errors.
| The default is 'strict' meaning that encoding errors raise a
| UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
| 'xmlcharrefreplace' as well as any other name registered with
| codecs.register_error that can handle UnicodeEncodeErrors.
|
| endswith(...)
| S.endswith(suffix[, start[, end]]) -> bool
|
| Return True if S ends with the specified suffix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| suffix can also be a tuple of strings to try.
|
| expandtabs(self, /, tabsize=8)
| Return a copy where all tab characters are expanded using spaces.
|
| If tabsize is not given, a tab size of 8 characters is assumed.
|
| find(...)
| S.find(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| format(...)
| S.format(*args, **kwargs) -> str
|
| Return a formatted version of S, using substitutions from args and kwargs.
| The substitutions are identified by braces ('{' and '}').
|
| format_map(...)
| S.format_map(mapping) -> str
|
| Return a formatted version of S, using substitutions from mapping.
| The substitutions are identified by braces ('{' and '}').
|
| index(...)
| S.index(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| isalnum(self, /)
| Return True if the string is an alpha-numeric string, False otherwise.
|
| A string is alpha-numeric if all characters in the string are alpha-numeric and
| there is at least one character in the string.
|
| isalpha(self, /)
| Return True if the string is an alphabetic string, False otherwise.
|
| A string is alphabetic if all characters in the string are alphabetic and there
| is at least one character in the string.
|
| isascii(self, /)
| Return True if all characters in the string are ASCII, False otherwise.
|
| ASCII characters have code points in the range U+0000-U+007F.
| Empty string is ASCII too.
|
| isdecimal(self, /)
| Return True if the string is a decimal string, False otherwise.
|
| A string is a decimal string if all characters in the string are decimal and
| there is at least one character in the string.
|
| isdigit(self, /)
| Return True if the string is a digit string, False otherwise.
|
| A string is a digit string if all characters in the string are digits and there
| is at least one character in the string.
|
| isidentifier(self, /)
| Return True if the string is a valid Python identifier, False otherwise.
|
| Call keyword.iskeyword(s) to test whether string s is a reserved identifier,
| such as "def" or "class".
|
| islower(self, /)
| Return True if the string is a lowercase string, False otherwise.
|
| A string is lowercase if all cased characters in the string are lowercase and
| there is at least one cased character in the string.
|
| isnumeric(self, /)
| Return True if the string is a numeric string, False otherwise.
|
| A string is numeric if all characters in the string are numeric and there is at
| least one character in the string.
|
| isprintable(self, /)
| Return True if the string is printable, False otherwise.
|
| A string is printable if all of its characters are considered printable in
| repr() or if it is empty.
|
| isspace(self, /)
| Return True if the string is a whitespace string, False otherwise.
|
| A string is whitespace if all characters in the string are whitespace and there
| is at least one character in the string.
|
| istitle(self, /)
| Return True if the string is a title-cased string, False otherwise.
|
| In a title-cased string, upper- and title-case characters may only
| follow uncased characters and lowercase characters only cased ones.
|
| isupper(self, /)
| Return True if the string is an uppercase string, False otherwise.
|
| A string is uppercase if all cased characters in the string are uppercase and
| there is at least one cased character in the string.
|
| join(self, iterable, /)
| Concatenate any number of strings.
|
| The string whose method is called is inserted in between each given string.
| The result is returned as a new string.
|
| Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
|
| ljust(self, width, fillchar=' ', /)
| Return a left-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| lower(self, /)
| Return a copy of the string converted to lowercase.
|
| lstrip(self, chars=None, /)
| Return a copy of the string with leading whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| partition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string. If the separator is found,
| returns a 3-tuple containing the part before the separator, the separator
| itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing the original string
| and two empty strings.
|
| removeprefix(self, prefix, /)
| Return a str with the given prefix string removed if present.
|
| If the string starts with the prefix string, return string[len(prefix):].
| Otherwise, return a copy of the original string.
|
| removesuffix(self, suffix, /)
| Return a str with the given suffix string removed if present.
|
| If the string ends with the suffix string and that suffix is not empty,
| return string[:-len(suffix)]. Otherwise, return a copy of the original
| string.
|
| replace(self, old, new, count=-1, /)
| Return a copy with all occurrences of substring old replaced by new.
|
| count
| Maximum number of occurrences to replace.
| -1 (the default value) means replace all occurrences.
|
| If the optional argument count is given, only the first count occurrences are
| replaced.
|
| rfind(...)
| S.rfind(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| rindex(...)
| S.rindex(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| rjust(self, width, fillchar=' ', /)
| Return a right-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| rpartition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string, starting at the end. If
| the separator is found, returns a 3-tuple containing the part before the
| separator, the separator itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing two empty strings
| and the original string.
|
| rsplit(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the end of the string and works to the front.
|
| rstrip(self, chars=None, /)
| Return a copy of the string with trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| split(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the front of the string and works to the end.
|
| Note, str.split() is mainly useful for data that has been intentionally
| delimited. With natural text that includes punctuation, consider using
| the regular expression module.
|
| splitlines(self, /, keepends=False)
| Return a list of the lines in the string, breaking at line boundaries.
|
| Line breaks are not included in the resulting list unless keepends is given and
| true.
|
| startswith(...)
| S.startswith(prefix[, start[, end]]) -> bool
|
| Return True if S starts with the specified prefix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| prefix can also be a tuple of strings to try.
|
| strip(self, chars=None, /)
| Return a copy of the string with leading and trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| swapcase(self, /)
| Convert uppercase characters to lowercase and lowercase characters to uppercase.
|
| title(self, /)
| Return a version of the string where each word is titlecased.
|
| More specifically, words start with uppercased characters and all remaining
| cased characters have lower case.
|
| translate(self, table, /)
| Replace each character in the string using the given translation table.
|
| table
| Translation table, which must be a mapping of Unicode ordinals to
| Unicode ordinals, strings, or None.
|
| The table must implement lookup/indexing via __getitem__, for instance a
| dictionary or list. If this operation raises LookupError, the character is
| left untouched. Characters mapped to None are deleted.
|
| upper(self, /)
| Return a copy of the string converted to uppercase.
|
| zfill(self, width, /)
| Pad a numeric string with zeros on the left, to fill a field of the given width.
|
| The string is never truncated.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.str:
|
| maketrans(...)
| Return a translation table usable for str.translate().
|
| If there is only one argument, it must be a dictionary mapping Unicode
| ordinals (integers) or characters to Unicode ordinals, strings or None.
| Character keys will be then converted to ordinals.
| If there are two arguments, they must be strings of equal length, and
| in the resulting dictionary, each character in x will be mapped to the
| character at the same position in y. If there is a third argument, it
| must be a string, whose characters will be mapped to None in the result.
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class TraceState(builtins.str, enum.Enum)
| TraceState(*values)
|
| Enum representing the state of a trace.
|
| - ``STATE_UNSPECIFIED``: Unspecified trace state.
| - ``OK``: Trace successfully completed.
| - ``ERROR``: Trace encountered an error.
| - ``IN_PROGRESS``: Trace is currently in progress.
|
| Method resolution order:
| TraceState
| builtins.str
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec) from enum.Enum
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__(self)
| Return str(self).
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| ERROR = <TraceState.ERROR: 'ERROR'>
|
| IN_PROGRESS = <TraceState.IN_PROGRESS: 'IN_PROGRESS'>
|
| OK = <TraceState.OK: 'OK'>
|
| STATE_UNSPECIFIED = <TraceState.STATE_UNSPECIFIED: 'STATE_UNSPECIFIED'...
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.str:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(...)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __sizeof__(self, /)
| Return the size of the string in memory, in bytes.
|
| capitalize(self, /)
| Return a capitalized version of the string.
|
| More specifically, make the first character have upper case and the rest lower
| case.
|
| casefold(self, /)
| Return a version of the string suitable for caseless comparisons.
|
| center(self, width, fillchar=' ', /)
| Return a centered string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| count(...)
| S.count(sub[, start[, end]]) -> int
|
| Return the number of non-overlapping occurrences of substring sub in
| string S[start:end]. Optional arguments start and end are
| interpreted as in slice notation.
|
| encode(self, /, encoding='utf-8', errors='strict')
| Encode the string using the codec registered for encoding.
|
| encoding
| The encoding in which to encode the string.
| errors
| The error handling scheme to use for encoding errors.
| The default is 'strict' meaning that encoding errors raise a
| UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
| 'xmlcharrefreplace' as well as any other name registered with
| codecs.register_error that can handle UnicodeEncodeErrors.
|
| endswith(...)
| S.endswith(suffix[, start[, end]]) -> bool
|
| Return True if S ends with the specified suffix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| suffix can also be a tuple of strings to try.
|
| expandtabs(self, /, tabsize=8)
| Return a copy where all tab characters are expanded using spaces.
|
| If tabsize is not given, a tab size of 8 characters is assumed.
|
| find(...)
| S.find(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| format(...)
| S.format(*args, **kwargs) -> str
|
| Return a formatted version of S, using substitutions from args and kwargs.
| The substitutions are identified by braces ('{' and '}').
|
| format_map(...)
| S.format_map(mapping) -> str
|
| Return a formatted version of S, using substitutions from mapping.
| The substitutions are identified by braces ('{' and '}').
|
| index(...)
| S.index(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| isalnum(self, /)
| Return True if the string is an alpha-numeric string, False otherwise.
|
| A string is alpha-numeric if all characters in the string are alpha-numeric and
| there is at least one character in the string.
|
| isalpha(self, /)
| Return True if the string is an alphabetic string, False otherwise.
|
| A string is alphabetic if all characters in the string are alphabetic and there
| is at least one character in the string.
|
| isascii(self, /)
| Return True if all characters in the string are ASCII, False otherwise.
|
| ASCII characters have code points in the range U+0000-U+007F.
| Empty string is ASCII too.
|
| isdecimal(self, /)
| Return True if the string is a decimal string, False otherwise.
|
| A string is a decimal string if all characters in the string are decimal and
| there is at least one character in the string.
|
| isdigit(self, /)
| Return True if the string is a digit string, False otherwise.
|
| A string is a digit string if all characters in the string are digits and there
| is at least one character in the string.
|
| isidentifier(self, /)
| Return True if the string is a valid Python identifier, False otherwise.
|
| Call keyword.iskeyword(s) to test whether string s is a reserved identifier,
| such as "def" or "class".
|
| islower(self, /)
| Return True if the string is a lowercase string, False otherwise.
|
| A string is lowercase if all cased characters in the string are lowercase and
| there is at least one cased character in the string.
|
| isnumeric(self, /)
| Return True if the string is a numeric string, False otherwise.
|
| A string is numeric if all characters in the string are numeric and there is at
| least one character in the string.
|
| isprintable(self, /)
| Return True if the string is printable, False otherwise.
|
| A string is printable if all of its characters are considered printable in
| repr() or if it is empty.
|
| isspace(self, /)
| Return True if the string is a whitespace string, False otherwise.
|
| A string is whitespace if all characters in the string are whitespace and there
| is at least one character in the string.
|
| istitle(self, /)
| Return True if the string is a title-cased string, False otherwise.
|
| In a title-cased string, upper- and title-case characters may only
| follow uncased characters and lowercase characters only cased ones.
|
| isupper(self, /)
| Return True if the string is an uppercase string, False otherwise.
|
| A string is uppercase if all cased characters in the string are uppercase and
| there is at least one cased character in the string.
|
| join(self, iterable, /)
| Concatenate any number of strings.
|
| The string whose method is called is inserted in between each given string.
| The result is returned as a new string.
|
| Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
|
| ljust(self, width, fillchar=' ', /)
| Return a left-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| lower(self, /)
| Return a copy of the string converted to lowercase.
|
| lstrip(self, chars=None, /)
| Return a copy of the string with leading whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| partition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string. If the separator is found,
| returns a 3-tuple containing the part before the separator, the separator
| itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing the original string
| and two empty strings.
|
| removeprefix(self, prefix, /)
| Return a str with the given prefix string removed if present.
|
| If the string starts with the prefix string, return string[len(prefix):].
| Otherwise, return a copy of the original string.
|
| removesuffix(self, suffix, /)
| Return a str with the given suffix string removed if present.
|
| If the string ends with the suffix string and that suffix is not empty,
| return string[:-len(suffix)]. Otherwise, return a copy of the original
| string.
|
| replace(self, old, new, count=-1, /)
| Return a copy with all occurrences of substring old replaced by new.
|
| count
| Maximum number of occurrences to replace.
| -1 (the default value) means replace all occurrences.
|
| If the optional argument count is given, only the first count occurrences are
| replaced.
|
| rfind(...)
| S.rfind(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| rindex(...)
| S.rindex(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| rjust(self, width, fillchar=' ', /)
| Return a right-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| rpartition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string, starting at the end. If
| the separator is found, returns a 3-tuple containing the part before the
| separator, the separator itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing two empty strings
| and the original string.
|
| rsplit(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the end of the string and works to the front.
|
| rstrip(self, chars=None, /)
| Return a copy of the string with trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| split(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the front of the string and works to the end.
|
| Note, str.split() is mainly useful for data that has been intentionally
| delimited. With natural text that includes punctuation, consider using
| the regular expression module.
|
| splitlines(self, /, keepends=False)
| Return a list of the lines in the string, breaking at line boundaries.
|
| Line breaks are not included in the resulting list unless keepends is given and
| true.
|
| startswith(...)
| S.startswith(prefix[, start[, end]]) -> bool
|
| Return True if S starts with the specified prefix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| prefix can also be a tuple of strings to try.
|
| strip(self, chars=None, /)
| Return a copy of the string with leading and trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| swapcase(self, /)
| Convert uppercase characters to lowercase and lowercase characters to uppercase.
|
| title(self, /)
| Return a version of the string where each word is titlecased.
|
| More specifically, words start with uppercased characters and all remaining
| cased characters have lower case.
|
| translate(self, table, /)
| Replace each character in the string using the given translation table.
|
| table
| Translation table, which must be a mapping of Unicode ordinals to
| Unicode ordinals, strings, or None.
|
| The table must implement lookup/indexing via __getitem__, for instance a
| dictionary or list. If this operation raises LookupError, the character is
| left untouched. Characters mapped to None are deleted.
|
| upper(self, /)
| Return a copy of the string converted to uppercase.
|
| zfill(self, width, /)
| Pad a numeric string with zeros on the left, to fill a field of the given width.
|
| The string is never truncated.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.str:
|
| maketrans(...)
| Return a translation table usable for str.translate().
|
| If there is only one argument, it must be a dictionary mapping Unicode
| ordinals (integers) or characters to Unicode ordinals, strings or None.
| Character keys will be then converted to ordinals.
| If there are two arguments, they must be strings of equal length, and
| in the resulting dictionary, each character in x will be mapped to the
| character at the same position in y. If there is a third argument, it
| must be a string, whose characters will be mapped to None in the result.
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class UCSchemaLocation(TraceLocationBase)
| UCSchemaLocation(catalog_name: str, schema_name: str, _otel_spans_table_name: str | None = 'mlflow_experiment_trace_otel_spans', _otel_logs_table_name: str | None = 'mlflow_experiment_trace_otel_logs') -> None
|
| Represents the location of a Databricks Unity Catalog (UC) schema.
|
| Args:
| catalog_name: The name of the Unity Catalog catalog name.
| schema_name: The name of the Unity Catalog schema.
|
| Method resolution order:
| UCSchemaLocation
| TraceLocationBase
| mlflow.entities._mlflow_object._MlflowObject
| abc.ABC
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, catalog_name: str, schema_name: str, _otel_spans_table_name: str | None = 'mlflow_experiment_trace_otel_spans', _otel_logs_table_name: str | None = 'mlflow_experiment_trace_otel_logs') -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| to_dict(self) -> dict[str, typing.Any]
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dict(d: dict[str, typing.Any]) -> 'UCSchemaLocation'
|
| from_proto(proto) -> 'UCSchemaLocation'
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| full_otel_logs_table_name
|
| full_otel_spans_table_name
|
| schema_location
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset()
|
| __annotations__ = {'_otel_logs_table_name': str | None, '_otel_spans_t...
|
| __dataclass_fields__ = {'_otel_logs_table_name': Field(name='_otel_log...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('catalog_name', 'schema_name', '_otel_spans_table_na...
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class UnityCatalog(TraceLocationBase)
| UnityCatalog(catalog_name: str, schema_name: str, table_prefix: str | None = None, _otel_spans_table_name: str | None = None, _otel_logs_table_name: str | None = None, _annotations_table_name: str | None = None) -> None
|
| .. Note:: Experimental: This class may change or be removed in a future release without warning.
|
|
| Represents a Databricks Unity Catalog location with a table prefix.
|
| Note: Arclight catalogs are not supported.
|
| Args:
| catalog_name: The name of the Unity Catalog catalog.
| schema_name: The name of the Unity Catalog schema.
| table_prefix: The prefix for tables in this location.
|
| Method resolution order:
| UnityCatalog
| TraceLocationBase
| mlflow.entities._mlflow_object._MlflowObject
| abc.ABC
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other: object) -> bool
| Return self==value.
|
| __init__(self, catalog_name: str, schema_name: str, table_prefix: str | None = None, _otel_spans_table_name: str | None = None, _otel_logs_table_name: str | None = None, _annotations_table_name: str | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self) -> str
| Return repr(self).
|
| to_dict(self) -> dict[str, typing.Any]
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dict(d: dict[str, typing.Any]) -> 'UnityCatalog'
|
| from_proto(proto) -> 'UnityCatalog'
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| full_annotations_table_name
|
| full_otel_logs_table_name
|
| full_otel_spans_table_name
|
| full_table_prefix
|
| schema_location
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset()
|
| __annotations__ = {'_annotations_table_name': str | None, '_otel_logs_...
|
| __dataclass_fields__ = {'_annotations_table_name': Field(name='_annota...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('catalog_name', 'schema_name', 'table_prefix', '_ote...
|
| table_prefix = None
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class ViewType(builtins.object)
| Enum to filter requested experiment types.
|
| Class methods defined here:
|
| from_proto(proto_view_type)
|
| from_string(view_str)
|
| to_proto(view_type)
|
| to_string(view_type)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| ACTIVE_ONLY = 1
|
| ALL = 3
|
| DELETED_ONLY = 2
class Webhook(builtins.object)
| Webhook(webhook_id: str, name: str, url: str, events: list[mlflow.entities.webhook.WebhookEvent], creation_timestamp: int, last_updated_timestamp: int, description: str | None = None, status: str | mlflow.entities.webhook.WebhookStatus = <WebhookStatus.ACTIVE: 'ACTIVE'>, secret: str | None = None, workspace: str | None = None)
|
| MLflow entity for Webhook.
|
| Methods defined here:
|
| __init__(self, webhook_id: str, name: str, url: str, events: list[mlflow.entities.webhook.WebhookEvent], creation_timestamp: int, last_updated_timestamp: int, description: str | None = None, status: str | mlflow.entities.webhook.WebhookStatus = <WebhookStatus.ACTIVE: 'ACTIVE'>, secret: str | None = None, workspace: str | None = None)
| Initialize a Webhook entity.
|
| Args:
| webhook_id: Unique webhook identifier
| name: Human-readable webhook name
| url: Webhook endpoint URL
| events: List of WebhookEvent objects that trigger this webhook
| creation_timestamp: Creation timestamp in milliseconds since Unix epoch
| last_updated_timestamp: Last update timestamp in milliseconds since Unix epoch
| description: Optional webhook description
| status: Webhook status (ACTIVE or DISABLED)
| secret: Optional secret key for HMAC signature verification
| workspace: Workspace the webhook belongs to
|
| __repr__(self) -> str
| Return repr(self).
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto: webhooks_pb2.Webhook) -> Self
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| creation_timestamp
|
| description
|
| events
|
| last_updated_timestamp
|
| name
|
| secret
|
| status
|
| url
|
| webhook_id
|
| workspace
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class WebhookEvent(builtins.object)
| WebhookEvent(entity: str | mlflow.entities.webhook.WebhookEntity, action: str | mlflow.entities.webhook.WebhookAction)
|
| Represents a webhook event with a resource and action.
|
| Methods defined here:
|
| __eq__(self, other: object) -> bool
| Return self==value.
|
| __hash__(self) -> int
| Return hash(self).
|
| __init__(self, entity: str | mlflow.entities.webhook.WebhookEntity, action: str | mlflow.entities.webhook.WebhookAction)
| Initialize a WebhookEvent.
|
| Args:
| entity: The entity type (string or WebhookEntity enum)
| action: The action type (string or WebhookAction enum)
|
| Raises:
| MlflowException: If the entity/action combination is invalid
|
| __repr__(self) -> str
| Return repr(self).
|
| __str__(self) -> str
| Return str(self).
|
| to_proto(self) -> webhooks_pb2.WebhookEvent
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto: webhooks_pb2.WebhookEvent) -> Self
|
| from_str(event_str: Literal['registered_model.created', 'model_version.created', 'model_version_tag.set', 'model_version_tag.deleted', 'model_version_alias.created', 'model_version_alias.deleted', 'prompt.created', 'prompt_version.created', 'prompt_tag.set', 'prompt_tag.deleted', 'prompt_version_tag.set', 'prompt_version_tag.deleted', 'prompt_alias.created', 'prompt_alias.deleted', 'budget_policy.exceeded']) -> Self
| Create a WebhookEvent from a dot-separated string representation.
|
| Args:
| event_str: Valid webhook event string (e.g., "registered_model.created")
|
| Returns:
| A WebhookEvent instance
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| action
|
| entity
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class WebhookStatus(builtins.str, enum.Enum)
| WebhookStatus(*values)
|
| Method resolution order:
| WebhookStatus
| builtins.str
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec) from enum.Enum
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__(self) -> str
| Return str(self).
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| ACTIVE = <WebhookStatus.ACTIVE: 'ACTIVE'>
|
| DISABLED = <WebhookStatus.DISABLED: 'DISABLED'>
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.str:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(...)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __sizeof__(self, /)
| Return the size of the string in memory, in bytes.
|
| capitalize(self, /)
| Return a capitalized version of the string.
|
| More specifically, make the first character have upper case and the rest lower
| case.
|
| casefold(self, /)
| Return a version of the string suitable for caseless comparisons.
|
| center(self, width, fillchar=' ', /)
| Return a centered string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| count(...)
| S.count(sub[, start[, end]]) -> int
|
| Return the number of non-overlapping occurrences of substring sub in
| string S[start:end]. Optional arguments start and end are
| interpreted as in slice notation.
|
| encode(self, /, encoding='utf-8', errors='strict')
| Encode the string using the codec registered for encoding.
|
| encoding
| The encoding in which to encode the string.
| errors
| The error handling scheme to use for encoding errors.
| The default is 'strict' meaning that encoding errors raise a
| UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
| 'xmlcharrefreplace' as well as any other name registered with
| codecs.register_error that can handle UnicodeEncodeErrors.
|
| endswith(...)
| S.endswith(suffix[, start[, end]]) -> bool
|
| Return True if S ends with the specified suffix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| suffix can also be a tuple of strings to try.
|
| expandtabs(self, /, tabsize=8)
| Return a copy where all tab characters are expanded using spaces.
|
| If tabsize is not given, a tab size of 8 characters is assumed.
|
| find(...)
| S.find(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| format(...)
| S.format(*args, **kwargs) -> str
|
| Return a formatted version of S, using substitutions from args and kwargs.
| The substitutions are identified by braces ('{' and '}').
|
| format_map(...)
| S.format_map(mapping) -> str
|
| Return a formatted version of S, using substitutions from mapping.
| The substitutions are identified by braces ('{' and '}').
|
| index(...)
| S.index(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| isalnum(self, /)
| Return True if the string is an alpha-numeric string, False otherwise.
|
| A string is alpha-numeric if all characters in the string are alpha-numeric and
| there is at least one character in the string.
|
| isalpha(self, /)
| Return True if the string is an alphabetic string, False otherwise.
|
| A string is alphabetic if all characters in the string are alphabetic and there
| is at least one character in the string.
|
| isascii(self, /)
| Return True if all characters in the string are ASCII, False otherwise.
|
| ASCII characters have code points in the range U+0000-U+007F.
| Empty string is ASCII too.
|
| isdecimal(self, /)
| Return True if the string is a decimal string, False otherwise.
|
| A string is a decimal string if all characters in the string are decimal and
| there is at least one character in the string.
|
| isdigit(self, /)
| Return True if the string is a digit string, False otherwise.
|
| A string is a digit string if all characters in the string are digits and there
| is at least one character in the string.
|
| isidentifier(self, /)
| Return True if the string is a valid Python identifier, False otherwise.
|
| Call keyword.iskeyword(s) to test whether string s is a reserved identifier,
| such as "def" or "class".
|
| islower(self, /)
| Return True if the string is a lowercase string, False otherwise.
|
| A string is lowercase if all cased characters in the string are lowercase and
| there is at least one cased character in the string.
|
| isnumeric(self, /)
| Return True if the string is a numeric string, False otherwise.
|
| A string is numeric if all characters in the string are numeric and there is at
| least one character in the string.
|
| isprintable(self, /)
| Return True if the string is printable, False otherwise.
|
| A string is printable if all of its characters are considered printable in
| repr() or if it is empty.
|
| isspace(self, /)
| Return True if the string is a whitespace string, False otherwise.
|
| A string is whitespace if all characters in the string are whitespace and there
| is at least one character in the string.
|
| istitle(self, /)
| Return True if the string is a title-cased string, False otherwise.
|
| In a title-cased string, upper- and title-case characters may only
| follow uncased characters and lowercase characters only cased ones.
|
| isupper(self, /)
| Return True if the string is an uppercase string, False otherwise.
|
| A string is uppercase if all cased characters in the string are uppercase and
| there is at least one cased character in the string.
|
| join(self, iterable, /)
| Concatenate any number of strings.
|
| The string whose method is called is inserted in between each given string.
| The result is returned as a new string.
|
| Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
|
| ljust(self, width, fillchar=' ', /)
| Return a left-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| lower(self, /)
| Return a copy of the string converted to lowercase.
|
| lstrip(self, chars=None, /)
| Return a copy of the string with leading whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| partition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string. If the separator is found,
| returns a 3-tuple containing the part before the separator, the separator
| itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing the original string
| and two empty strings.
|
| removeprefix(self, prefix, /)
| Return a str with the given prefix string removed if present.
|
| If the string starts with the prefix string, return string[len(prefix):].
| Otherwise, return a copy of the original string.
|
| removesuffix(self, suffix, /)
| Return a str with the given suffix string removed if present.
|
| If the string ends with the suffix string and that suffix is not empty,
| return string[:-len(suffix)]. Otherwise, return a copy of the original
| string.
|
| replace(self, old, new, count=-1, /)
| Return a copy with all occurrences of substring old replaced by new.
|
| count
| Maximum number of occurrences to replace.
| -1 (the default value) means replace all occurrences.
|
| If the optional argument count is given, only the first count occurrences are
| replaced.
|
| rfind(...)
| S.rfind(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| rindex(...)
| S.rindex(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| rjust(self, width, fillchar=' ', /)
| Return a right-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| rpartition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string, starting at the end. If
| the separator is found, returns a 3-tuple containing the part before the
| separator, the separator itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing two empty strings
| and the original string.
|
| rsplit(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the end of the string and works to the front.
|
| rstrip(self, chars=None, /)
| Return a copy of the string with trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| split(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the front of the string and works to the end.
|
| Note, str.split() is mainly useful for data that has been intentionally
| delimited. With natural text that includes punctuation, consider using
| the regular expression module.
|
| splitlines(self, /, keepends=False)
| Return a list of the lines in the string, breaking at line boundaries.
|
| Line breaks are not included in the resulting list unless keepends is given and
| true.
|
| startswith(...)
| S.startswith(prefix[, start[, end]]) -> bool
|
| Return True if S starts with the specified prefix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| prefix can also be a tuple of strings to try.
|
| strip(self, chars=None, /)
| Return a copy of the string with leading and trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| swapcase(self, /)
| Convert uppercase characters to lowercase and lowercase characters to uppercase.
|
| title(self, /)
| Return a version of the string where each word is titlecased.
|
| More specifically, words start with uppercased characters and all remaining
| cased characters have lower case.
|
| translate(self, table, /)
| Replace each character in the string using the given translation table.
|
| table
| Translation table, which must be a mapping of Unicode ordinals to
| Unicode ordinals, strings, or None.
|
| The table must implement lookup/indexing via __getitem__, for instance a
| dictionary or list. If this operation raises LookupError, the character is
| left untouched. Characters mapped to None are deleted.
|
| upper(self, /)
| Return a copy of the string converted to uppercase.
|
| zfill(self, width, /)
| Pad a numeric string with zeros on the left, to fill a field of the given width.
|
| The string is never truncated.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.str:
|
| maketrans(...)
| Return a translation table usable for str.translate().
|
| If there is only one argument, it must be a dictionary mapping Unicode
| ordinals (integers) or characters to Unicode ordinals, strings or None.
| Character keys will be then converted to ordinals.
| If there are two arguments, they must be strings of equal length, and
| in the resulting dictionary, each character in x will be mapped to the
| character at the same position in y. If there is a third argument, it
| must be a string, whose characters will be mapped to None in the result.
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class WebhookTestResult(builtins.object)
| WebhookTestResult(success: bool, response_status: int | None = None, response_body: str | None = None, error_message: str | None = None)
|
| MLflow entity for WebhookTestResult.
|
| Methods defined here:
|
| __init__(self, success: bool, response_status: int | None = None, response_body: str | None = None, error_message: str | None = None)
| Initialize a WebhookTestResult entity.
|
| Args:
| success: Whether the test succeeded
| response_status: HTTP response status code if available
| response_body: Response body if available
| error_message: Error message if test failed
|
| __repr__(self) -> str
| Return repr(self).
|
| to_proto(self) -> webhooks_pb2.WebhookTestResult
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto: webhooks_pb2.WebhookTestResult) -> Self
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| error_message
|
| response_body
|
| response_status
|
| success
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class Workspace(builtins.object)
| Workspace(name: 'str', description: 'str | None' = None, default_artifact_root: 'str | None' = None, trace_archival_location: 'str | None' = None, trace_archival_retention: 'str | None' = None) -> None
|
| Minimal metadata describing a workspace.
|
| Methods defined here:
|
| __delattr__(self, name)
| Implement delattr(self, name).
|
| __eq__(self, other)
| Return self==value.
|
| __getstate__ = _dataclass_getstate(self) from dataclasses
| # _dataclass_getstate and _dataclass_setstate are needed for pickling frozen
| # classes with slots. These could be slightly more performant if we generated
| # the code instead of iterating over fields. But that can be a project for
| # another day, if performance becomes an issue.
|
| __hash__(self)
| Return hash(self).
|
| __init__(self, name: 'str', description: 'str | None' = None, default_artifact_root: 'str | None' = None, trace_archival_location: 'str | None' = None, trace_archival_retention: 'str | None' = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| __setattr__(self, name, value)
| Implement setattr(self, name, value).
|
| __setstate__ = _dataclass_setstate(self, state) from dataclasses
|
| to_dict(self) -> 'dict[str, Any]'
|
| to_proto(self) -> 'ProtoWorkspace'
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dict(payload: 'dict[str, Any]') -> "'Workspace'"
|
| from_proto(proto: 'ProtoWorkspace') -> "'Workspace'"
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| default_artifact_root
|
| description
|
| name
|
| trace_archival_location
|
| trace_archival_retention
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'default_artifact_root': 'str | None', 'description...
|
| __dataclass_fields__ = {'default_artifact_root': Field(name='default_a...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __match_args__ = ('name', 'description', 'default_artifact_root', 'tra...
class WorkspaceDeletionMode(builtins.str, enum.Enum)
| WorkspaceDeletionMode(*values)
|
| Controls what happens to resources when a workspace is deleted.
|
| Method resolution order:
| WorkspaceDeletionMode
| builtins.str
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec) from enum.Enum
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__(self) from enum.Enum
| Return str(self).
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| CASCADE = <WorkspaceDeletionMode.CASCADE: 'CASCADE'>
|
| RESTRICT = <WorkspaceDeletionMode.RESTRICT: 'RESTRICT'>
|
| SET_DEFAULT = <WorkspaceDeletionMode.SET_DEFAULT: 'SET_DEFAULT'>
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.str:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(...)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __sizeof__(self, /)
| Return the size of the string in memory, in bytes.
|
| capitalize(self, /)
| Return a capitalized version of the string.
|
| More specifically, make the first character have upper case and the rest lower
| case.
|
| casefold(self, /)
| Return a version of the string suitable for caseless comparisons.
|
| center(self, width, fillchar=' ', /)
| Return a centered string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| count(...)
| S.count(sub[, start[, end]]) -> int
|
| Return the number of non-overlapping occurrences of substring sub in
| string S[start:end]. Optional arguments start and end are
| interpreted as in slice notation.
|
| encode(self, /, encoding='utf-8', errors='strict')
| Encode the string using the codec registered for encoding.
|
| encoding
| The encoding in which to encode the string.
| errors
| The error handling scheme to use for encoding errors.
| The default is 'strict' meaning that encoding errors raise a
| UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
| 'xmlcharrefreplace' as well as any other name registered with
| codecs.register_error that can handle UnicodeEncodeErrors.
|
| endswith(...)
| S.endswith(suffix[, start[, end]]) -> bool
|
| Return True if S ends with the specified suffix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| suffix can also be a tuple of strings to try.
|
| expandtabs(self, /, tabsize=8)
| Return a copy where all tab characters are expanded using spaces.
|
| If tabsize is not given, a tab size of 8 characters is assumed.
|
| find(...)
| S.find(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| format(...)
| S.format(*args, **kwargs) -> str
|
| Return a formatted version of S, using substitutions from args and kwargs.
| The substitutions are identified by braces ('{' and '}').
|
| format_map(...)
| S.format_map(mapping) -> str
|
| Return a formatted version of S, using substitutions from mapping.
| The substitutions are identified by braces ('{' and '}').
|
| index(...)
| S.index(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| isalnum(self, /)
| Return True if the string is an alpha-numeric string, False otherwise.
|
| A string is alpha-numeric if all characters in the string are alpha-numeric and
| there is at least one character in the string.
|
| isalpha(self, /)
| Return True if the string is an alphabetic string, False otherwise.
|
| A string is alphabetic if all characters in the string are alphabetic and there
| is at least one character in the string.
|
| isascii(self, /)
| Return True if all characters in the string are ASCII, False otherwise.
|
| ASCII characters have code points in the range U+0000-U+007F.
| Empty string is ASCII too.
|
| isdecimal(self, /)
| Return True if the string is a decimal string, False otherwise.
|
| A string is a decimal string if all characters in the string are decimal and
| there is at least one character in the string.
|
| isdigit(self, /)
| Return True if the string is a digit string, False otherwise.
|
| A string is a digit string if all characters in the string are digits and there
| is at least one character in the string.
|
| isidentifier(self, /)
| Return True if the string is a valid Python identifier, False otherwise.
|
| Call keyword.iskeyword(s) to test whether string s is a reserved identifier,
| such as "def" or "class".
|
| islower(self, /)
| Return True if the string is a lowercase string, False otherwise.
|
| A string is lowercase if all cased characters in the string are lowercase and
| there is at least one cased character in the string.
|
| isnumeric(self, /)
| Return True if the string is a numeric string, False otherwise.
|
| A string is numeric if all characters in the string are numeric and there is at
| least one character in the string.
|
| isprintable(self, /)
| Return True if the string is printable, False otherwise.
|
| A string is printable if all of its characters are considered printable in
| repr() or if it is empty.
|
| isspace(self, /)
| Return True if the string is a whitespace string, False otherwise.
|
| A string is whitespace if all characters in the string are whitespace and there
| is at least one character in the string.
|
| istitle(self, /)
| Return True if the string is a title-cased string, False otherwise.
|
| In a title-cased string, upper- and title-case characters may only
| follow uncased characters and lowercase characters only cased ones.
|
| isupper(self, /)
| Return True if the string is an uppercase string, False otherwise.
|
| A string is uppercase if all cased characters in the string are uppercase and
| there is at least one cased character in the string.
|
| join(self, iterable, /)
| Concatenate any number of strings.
|
| The string whose method is called is inserted in between each given string.
| The result is returned as a new string.
|
| Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
|
| ljust(self, width, fillchar=' ', /)
| Return a left-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| lower(self, /)
| Return a copy of the string converted to lowercase.
|
| lstrip(self, chars=None, /)
| Return a copy of the string with leading whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| partition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string. If the separator is found,
| returns a 3-tuple containing the part before the separator, the separator
| itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing the original string
| and two empty strings.
|
| removeprefix(self, prefix, /)
| Return a str with the given prefix string removed if present.
|
| If the string starts with the prefix string, return string[len(prefix):].
| Otherwise, return a copy of the original string.
|
| removesuffix(self, suffix, /)
| Return a str with the given suffix string removed if present.
|
| If the string ends with the suffix string and that suffix is not empty,
| return string[:-len(suffix)]. Otherwise, return a copy of the original
| string.
|
| replace(self, old, new, count=-1, /)
| Return a copy with all occurrences of substring old replaced by new.
|
| count
| Maximum number of occurrences to replace.
| -1 (the default value) means replace all occurrences.
|
| If the optional argument count is given, only the first count occurrences are
| replaced.
|
| rfind(...)
| S.rfind(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| rindex(...)
| S.rindex(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| rjust(self, width, fillchar=' ', /)
| Return a right-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| rpartition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string, starting at the end. If
| the separator is found, returns a 3-tuple containing the part before the
| separator, the separator itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing two empty strings
| and the original string.
|
| rsplit(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the end of the string and works to the front.
|
| rstrip(self, chars=None, /)
| Return a copy of the string with trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| split(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the front of the string and works to the end.
|
| Note, str.split() is mainly useful for data that has been intentionally
| delimited. With natural text that includes punctuation, consider using
| the regular expression module.
|
| splitlines(self, /, keepends=False)
| Return a list of the lines in the string, breaking at line boundaries.
|
| Line breaks are not included in the resulting list unless keepends is given and
| true.
|
| startswith(...)
| S.startswith(prefix[, start[, end]]) -> bool
|
| Return True if S starts with the specified prefix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| prefix can also be a tuple of strings to try.
|
| strip(self, chars=None, /)
| Return a copy of the string with leading and trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| swapcase(self, /)
| Convert uppercase characters to lowercase and lowercase characters to uppercase.
|
| title(self, /)
| Return a version of the string where each word is titlecased.
|
| More specifically, words start with uppercased characters and all remaining
| cased characters have lower case.
|
| translate(self, table, /)
| Replace each character in the string using the given translation table.
|
| table
| Translation table, which must be a mapping of Unicode ordinals to
| Unicode ordinals, strings, or None.
|
| The table must implement lookup/indexing via __getitem__, for instance a
| dictionary or list. If this operation raises LookupError, the character is
| left untouched. Characters mapped to None are deleted.
|
| upper(self, /)
| Return a copy of the string converted to uppercase.
|
| zfill(self, width, /)
| Pad a numeric string with zeros on the left, to fill a field of the given width.
|
| The string is never truncated.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.str:
|
| maketrans(...)
| Return a translation table usable for str.translate().
|
| If there is only one argument, it must be a dictionary mapping Unicode
| ordinals (integers) or characters to Unicode ordinals, strings or None.
| Character keys will be then converted to ordinals.
| If there are two arguments, they must be strings of equal length, and
| in the resulting dictionary, each character in x will be mapped to the
| character at the same position in y. If there is a third argument, it
| must be a string, whose characters will be mapped to None in the result.
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class _DatasetSummary(builtins.object)
| _DatasetSummary(experiment_id, name, digest, context)
|
| DatasetSummary object.
|
| This is used to return a list of dataset summaries across one or more experiments in the UI.
|
| Methods defined here:
|
| __eq__(self, other) -> bool
| Return self==value.
|
| __init__(self, experiment_id, name, digest, context)
| Initialize self. See help(type(self)) for accurate signature.
|
| to_dict(self)
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| context
|
| digest
|
| experiment_id
|
| name
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __hash__ = None
FUNCTIONS
__getattr__(name)
Lazy loading for EvaluationDataset to avoid circular imports.
DATA
__all__ = ['Experiment', 'ExperimentTag', 'FileInfo', 'Metric', 'Param...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\entities\__init__.py
mlflow.environment_variables
Python Library Documentation: module mlflow.environment_variables in mlflow
NAME
mlflow.environment_variables
DESCRIPTION
This module defines environment variables used in MLflow.
MLflow's environment variables adhere to the following naming conventions:
- Public variables: environment variable names begin with `MLFLOW_`
- Internal-use variables: For variables used only internally, names start with `_MLFLOW_`
DATA
MLFLOW_ACTIVE_MODEL_ID = 'MLFLOW_ACTIVE_MODEL_ID'
MLFLOW_ALIAS_PROMPT_CACHE_TTL_SECONDS = 'MLFLOW_ALIAS_PROMPT_CACHE_TTL...
MLFLOW_ALLOW_FILE_STORE = 'MLFLOW_ALLOW_FILE_STORE'
MLFLOW_ALLOW_HTTP_REDIRECTS = 'MLFLOW_ALLOW_HTTP_REDIRECTS'
MLFLOW_ALLOW_PICKLE_DESERIALIZATION = 'MLFLOW_ALLOW_PICKLE_DESERIALIZA...
MLFLOW_ARTIFACT_LOCATION_MAX_LENGTH = 'MLFLOW_ARTIFACT_LOCATION_MAX_LE...
MLFLOW_ARTIFACT_UPLOAD_DOWNLOAD_TIMEOUT = 'MLFLOW_ARTIFACT_UPLOAD_DOWN...
MLFLOW_ASYNC_LOGGING_BUFFERING_SECONDS = 'MLFLOW_ASYNC_LOGGING_BUFFERI...
MLFLOW_ASYNC_LOGGING_THREADPOOL_SIZE = 'MLFLOW_ASYNC_LOGGING_THREADPOO...
MLFLOW_ASYNC_TRACE_LOGGING_MAX_INTERVAL_MILLIS = 'MLFLOW_ASYNC_TRACE_L...
MLFLOW_ASYNC_TRACE_LOGGING_MAX_QUEUE_SIZE = 'MLFLOW_ASYNC_TRACE_LOGGIN...
MLFLOW_ASYNC_TRACE_LOGGING_MAX_SPAN_BATCH_SIZE = 'MLFLOW_ASYNC_TRACE_L...
MLFLOW_ASYNC_TRACE_LOGGING_MAX_WORKERS = 'MLFLOW_ASYNC_TRACE_LOGGING_M...
MLFLOW_ASYNC_TRACE_LOGGING_RETRY_TIMEOUT = 'MLFLOW_ASYNC_TRACE_LOGGING...
MLFLOW_AUTH_CONFIG_PATH = 'MLFLOW_AUTH_CONFIG_PATH'
MLFLOW_BOTO_CLIENT_ADDRESSING_STYLE = 'MLFLOW_BOTO_CLIENT_ADDRESSING_S...
MLFLOW_CONDA_CREATE_ENV_CMD = 'MLFLOW_CONDA_CREATE_ENV_CMD'
MLFLOW_CONDA_HOME = 'MLFLOW_CONDA_HOME'
MLFLOW_CONFIGURE_LOGGING = 'MLFLOW_CONFIGURE_LOGGING'
MLFLOW_CONVERT_MESSAGES_DICT_FOR_LANGCHAIN = 'MLFLOW_CONVERT_MESSAGES_...
MLFLOW_CREATE_MODEL_VERSION_SOURCE_VALIDATION_REGEX = 'MLFLOW_CREATE_M...
MLFLOW_DATABRICKS_ENDPOINT_HTTP_RETRY_TIMEOUT = 'MLFLOW_DATABRICKS_END...
MLFLOW_DEFAULT_PREDICTION_DEVICE = 'MLFLOW_DEFAULT_PREDICTION_DEVICE'
MLFLOW_DEPLOYMENTS_CONFIG = 'MLFLOW_DEPLOYMENTS_CONFIG'
MLFLOW_DEPLOYMENTS_TARGET = 'MLFLOW_DEPLOYMENTS_TARGET'
MLFLOW_DEPLOYMENT_CLIENT_HTTP_REQUEST_TIMEOUT = 'MLFLOW_DEPLOYMENT_CLI...
MLFLOW_DEPLOYMENT_FLAVOR_NAME = 'MLFLOW_DEPLOYMENT_FLAVOR_NAME'
MLFLOW_DEPLOYMENT_PREDICT_TIMEOUT = 'MLFLOW_DEPLOYMENT_PREDICT_TIMEOUT...
MLFLOW_DEPLOYMENT_PREDICT_TOTAL_TIMEOUT = 'MLFLOW_DEPLOYMENT_PREDICT_T...
MLFLOW_DFS_TMP = 'MLFLOW_DFS_TMP'
MLFLOW_DISABLE_DATABRICKS_SDK_FOR_RUN_ARTIFACTS = 'MLFLOW_DISABLE_DATA...
MLFLOW_DISABLE_ENV_CREATION = 'MLFLOW_DISABLE_ENV_CREATION'
MLFLOW_DISABLE_ENV_MANAGER_CONDA_WARNING = 'MLFLOW_DISABLE_ENV_MANAGER...
MLFLOW_DISABLE_SCHEMA_DETAILS = 'MLFLOW_DISABLE_SCHEMA_DETAILS'
MLFLOW_DISABLE_TELEMETRY = 'MLFLOW_DISABLE_TELEMETRY'
MLFLOW_DOCKER_OPENJDK_VERSION = 'MLFLOW_DOCKER_OPENJDK_VERSION'
MLFLOW_DOWNLOAD_CHUNK_TIMEOUT = 'MLFLOW_DOWNLOAD_CHUNK_TIMEOUT'
MLFLOW_ENABLE_ARTIFACTS_PROGRESS_BAR = 'MLFLOW_ENABLE_ARTIFACTS_PROGRE...
MLFLOW_ENABLE_ASYNC_LOGGING = 'MLFLOW_ENABLE_ASYNC_LOGGING'
MLFLOW_ENABLE_ASYNC_TRACE_LOGGING = 'MLFLOW_ENABLE_ASYNC_TRACE_LOGGING...
MLFLOW_ENABLE_DBFS_FUSE_ARTIFACT_REPO = 'MLFLOW_ENABLE_DBFS_FUSE_ARTIF...
MLFLOW_ENABLE_DB_SDK = 'MLFLOW_ENABLE_DB_SDK'
MLFLOW_ENABLE_MCP_TOOL_DISCOVERY = 'MLFLOW_ENABLE_MCP_TOOL_DISCOVERY'
MLFLOW_ENABLE_MULTIPART_DOWNLOAD = 'MLFLOW_ENABLE_MULTIPART_DOWNLOAD'
MLFLOW_ENABLE_MULTIPART_UPLOAD = 'MLFLOW_ENABLE_MULTIPART_UPLOAD'
MLFLOW_ENABLE_OTEL_GENAI_SEMCONV = 'MLFLOW_ENABLE_OTEL_GENAI_SEMCONV'
MLFLOW_ENABLE_OTLP_EXPORTER = 'MLFLOW_ENABLE_OTLP_EXPORTER'
MLFLOW_ENABLE_PROXY_MULTIPART_DOWNLOAD = 'MLFLOW_ENABLE_PROXY_MULTIPAR...
MLFLOW_ENABLE_PROXY_MULTIPART_UPLOAD = 'MLFLOW_ENABLE_PROXY_MULTIPART_...
MLFLOW_ENABLE_REMOTE_ASSISTANT = 'MLFLOW_ENABLE_REMOTE_ASSISTANT'
MLFLOW_ENABLE_SYSTEM_METRICS_LOGGING = 'MLFLOW_ENABLE_SYSTEM_METRICS_L...
MLFLOW_ENABLE_UC_FUNCTIONS = 'MLFLOW_ENABLE_UC_FUNCTIONS'
MLFLOW_ENABLE_UC_NATIVE_MODEL_REGISTRY = 'MLFLOW_ENABLE_UC_NATIVE_MODE...
MLFLOW_ENABLE_UC_VOLUME_FUSE_ARTIFACT_REPO = 'MLFLOW_ENABLE_UC_VOLUME_...
MLFLOW_ENABLE_WORKSPACES = 'MLFLOW_ENABLE_WORKSPACES'
MLFLOW_ENFORCE_STDIN_SCORING_SERVER_FOR_SPARK_UDF = 'MLFLOW_ENFORCE_ST...
MLFLOW_ENV_ROOT = 'MLFLOW_ENV_ROOT'
MLFLOW_EXPERIMENT_ID = 'MLFLOW_EXPERIMENT_ID'
MLFLOW_EXPERIMENT_NAME = 'MLFLOW_EXPERIMENT_NAME'
MLFLOW_FLASK_SERVER_SECRET_KEY = 'MLFLOW_FLASK_SERVER_SECRET_KEY'
MLFLOW_GATEWAY_ALLOWED_PROVIDERS = 'MLFLOW_GATEWAY_ALLOWED_PROVIDERS'
MLFLOW_GATEWAY_BUDGET_REDIS_URL = 'MLFLOW_GATEWAY_BUDGET_REDIS_URL'
MLFLOW_GATEWAY_BUDGET_REFRESH_INTERVAL = 'MLFLOW_GATEWAY_BUDGET_REFRES...
MLFLOW_GATEWAY_CONFIG = 'MLFLOW_GATEWAY_CONFIG'
MLFLOW_GATEWAY_RATE_LIMITS_STORAGE_URI = 'MLFLOW_GATEWAY_RATE_LIMITS_S...
MLFLOW_GATEWAY_RESOLVE_API_KEY_FROM_ENV = 'MLFLOW_GATEWAY_RESOLVE_API_...
MLFLOW_GATEWAY_RESOLVE_API_KEY_FROM_FILE = 'MLFLOW_GATEWAY_RESOLVE_API...
MLFLOW_GATEWAY_ROUTE_TIMEOUT_SECONDS = 'MLFLOW_GATEWAY_ROUTE_TIMEOUT_S...
MLFLOW_GATEWAY_URI = 'MLFLOW_GATEWAY_URI'
MLFLOW_GCS_DOWNLOAD_CHUNK_SIZE = 'MLFLOW_GCS_DOWNLOAD_CHUNK_SIZE'
MLFLOW_GCS_UPLOAD_CHUNK_SIZE = 'MLFLOW_GCS_UPLOAD_CHUNK_SIZE'
MLFLOW_GENAI_DISCOVERY_TRIAGE_SAMPLE_SIZE = 'MLFLOW_GENAI_DISCOVERY_TR...
MLFLOW_GENAI_EVAL_ASYNC_TIMEOUT = 'MLFLOW_GENAI_EVAL_ASYNC_TIMEOUT'
MLFLOW_GENAI_EVAL_ENABLE_SCORER_TRACING = 'MLFLOW_GENAI_EVAL_ENABLE_SC...
MLFLOW_GENAI_EVAL_LLM_TIMEOUT = 'MLFLOW_GENAI_EVAL_LLM_TIMEOUT'
MLFLOW_GENAI_EVAL_MAX_RETRIES = 'MLFLOW_GENAI_EVAL_MAX_RETRIES'
MLFLOW_GENAI_EVAL_MAX_SCORER_WORKERS = 'MLFLOW_GENAI_EVAL_MAX_SCORER_W...
MLFLOW_GENAI_EVAL_MAX_WORKERS = 'MLFLOW_GENAI_EVAL_MAX_WORKERS'
MLFLOW_GENAI_EVAL_PREDICT_RATE_LIMIT = 'MLFLOW_GENAI_EVAL_PREDICT_RATE...
MLFLOW_GENAI_EVAL_SCORER_RATE_LIMIT = 'MLFLOW_GENAI_EVAL_SCORER_RATE_L...
MLFLOW_GENAI_EVAL_SKIP_TRACE_VALIDATION = 'MLFLOW_GENAI_EVAL_SKIP_TRAC...
MLFLOW_GENAI_JUDGE_BASE_URL = 'MLFLOW_GENAI_JUDGE_BASE_URL'
MLFLOW_GENAI_JUDGE_DEFAULT_MODEL = 'MLFLOW_GENAI_JUDGE_DEFAULT_MODEL'
MLFLOW_GENAI_OPTIMIZE_MAX_WORKERS = 'MLFLOW_GENAI_OPTIMIZE_MAX_WORKERS...
MLFLOW_GENAI_SIMULATOR_MAX_WORKERS = 'MLFLOW_GENAI_SIMULATOR_MAX_WORKE...
MLFLOW_GET_TRACE_OTEL_INITIAL_RETRY_INTERVAL_SECONDS = 'MLFLOW_GET_TRA...
MLFLOW_GET_TRACE_OTEL_MAX_RETRY_INTERVAL_SECONDS = 'MLFLOW_GET_TRACE_O...
MLFLOW_GET_TRACE_OTEL_RETRY_TIMEOUT_SECONDS = 'MLFLOW_GET_TRACE_OTEL_R...
MLFLOW_HTTP_POOL_CONNECTIONS = 'MLFLOW_HTTP_POOL_CONNECTIONS'
MLFLOW_HTTP_POOL_MAXSIZE = 'MLFLOW_HTTP_POOL_MAXSIZE'
MLFLOW_HTTP_REQUEST_BACKOFF_FACTOR = 'MLFLOW_HTTP_REQUEST_BACKOFF_FACT...
MLFLOW_HTTP_REQUEST_BACKOFF_JITTER = 'MLFLOW_HTTP_REQUEST_BACKOFF_JITT...
MLFLOW_HTTP_REQUEST_MAX_RETRIES = 'MLFLOW_HTTP_REQUEST_MAX_RETRIES'
MLFLOW_HTTP_REQUEST_TIMEOUT = 'MLFLOW_HTTP_REQUEST_TIMEOUT'
MLFLOW_HTTP_RESPECT_RETRY_AFTER_HEADER = 'MLFLOW_HTTP_RESPECT_RETRY_AF...
MLFLOW_HTTP_TCP_KEEPALIVE = 'MLFLOW_HTTP_TCP_KEEPALIVE'
MLFLOW_HTTP_TCP_KEEPALIVE_COUNT = 'MLFLOW_HTTP_TCP_KEEPALIVE_COUNT'
MLFLOW_HTTP_TCP_KEEPALIVE_IDLE = 'MLFLOW_HTTP_TCP_KEEPALIVE_IDLE'
MLFLOW_HTTP_TCP_KEEPALIVE_INTERVAL = 'MLFLOW_HTTP_TCP_KEEPALIVE_INTERV...
MLFLOW_HUGGINGFACE_DEVICE_MAP_STRATEGY = 'MLFLOW_HUGGINGFACE_DEVICE_MA...
MLFLOW_HUGGINGFACE_DISABLE_ACCELERATE_FEATURES = 'MLFLOW_DISABLE_HUGGI...
MLFLOW_HUGGINGFACE_MODEL_MAX_SHARD_SIZE = 'MLFLOW_HUGGINGFACE_MODEL_MA...
MLFLOW_HUGGINGFACE_USE_DEVICE_MAP = 'MLFLOW_HUGGINGFACE_USE_DEVICE_MAP...
MLFLOW_HUGGINGFACE_USE_LOW_CPU_MEM_USAGE = 'MLFLOW_HUGGINGFACE_USE_LOW...
MLFLOW_ICON_URL_ALLOWED_DOMAINS = 'MLFLOW_ICON_URL_ALLOWED_DOMAINS'
MLFLOW_ICON_URL_ALLOWED_SCHEMES = 'MLFLOW_ICON_URL_ALLOWED_SCHEMES'
MLFLOW_ICON_URL_ALLOW_PRIVATE_IPS = 'MLFLOW_ICON_URL_ALLOW_PRIVATE_IPS...
MLFLOW_INPUT_EXAMPLE_INFERENCE_TIMEOUT = 'MLFLOW_INPUT_EXAMPLE_INFEREN...
MLFLOW_JUDGE_MAX_ITERATIONS = 'MLFLOW_JUDGE_MAX_ITERATIONS'
MLFLOW_KERBEROS_TICKET_CACHE = 'MLFLOW_KERBEROS_TICKET_CACHE'
MLFLOW_KERBEROS_USER = 'MLFLOW_KERBEROS_USER'
MLFLOW_LOCK_MODEL_DEPENDENCIES = 'MLFLOW_LOCK_MODEL_DEPENDENCIES'
MLFLOW_LOGGING_LEVEL = 'MLFLOW_LOGGING_LEVEL'
MLFLOW_LOG_MODEL_COMPRESSION = 'MLFLOW_LOG_MODEL_COMPRESSION'
MLFLOW_LOG_UV_FILES = 'MLFLOW_LOG_UV_FILES'
MLFLOW_MAX_TRACES_TO_DISPLAY_IN_NOTEBOOK = 'MLFLOW_MAX_TRACES_TO_DISPL...
MLFLOW_MODEL_CATALOG_CACHE_TTL = 'MLFLOW_MODEL_CATALOG_CACHE_TTL'
MLFLOW_MODEL_CATALOG_URI = 'MLFLOW_MODEL_CATALOG_URI'
MLFLOW_MODEL_ENV_DOWNLOADING_TEMP_DIR = 'MLFLOW_MODEL_ENV_DOWNLOADING_...
MLFLOW_MULTIPART_DOWNLOAD_CHUNK_SIZE = 'MLFLOW_MULTIPART_DOWNLOAD_CHUN...
MLFLOW_MULTIPART_DOWNLOAD_MINIMUM_FILE_SIZE = 'MLFLOW_MULTIPART_DOWNLO...
MLFLOW_MULTIPART_UPLOAD_CHUNK_SIZE = 'MLFLOW_MULTIPART_UPLOAD_CHUNK_SI...
MLFLOW_MULTIPART_UPLOAD_MINIMUM_FILE_SIZE = 'MLFLOW_MULTIPART_UPLOAD_M...
MLFLOW_MYSQL_SSL_CA = 'MLFLOW_MYSQL_SSL_CA'
MLFLOW_MYSQL_SSL_CERT = 'MLFLOW_MYSQL_SSL_CERT'
MLFLOW_MYSQL_SSL_KEY = 'MLFLOW_MYSQL_SSL_KEY'
MLFLOW_NOTEBOOK_TRACE_RENDERER_BASE_URL = 'MLFLOW_NOTEBOOK_TRACE_RENDE...
MLFLOW_ONLINE_SCORING_DEFAULT_SESSION_COMPLETION_BUFFER_SECONDS = 'MLF...
MLFLOW_ONLINE_SCORING_MAX_WORKER_THREADS = 'MLFLOW_ONLINE_SCORING_MAX_...
MLFLOW_OPENAI_SECRET_SCOPE = 'MLFLOW_OPENAI_SECRET_SCOPE'
MLFLOW_PRESIGNED_DOWNLOAD_URL_TTL_SECONDS = 'MLFLOW_PRESIGNED_DOWNLOAD...
MLFLOW_PRINT_MODEL_URLS_ON_CREATION = 'MLFLOW_PRINT_MODEL_URLS_ON_CREA...
MLFLOW_PROMPT_CACHE_MAX_SIZE = 'MLFLOW_PROMPT_CACHE_MAX_SIZE'
MLFLOW_PYARROW_EXTRA_CONF = 'MLFLOW_PYARROW_EXTRA_CONF'
MLFLOW_RBAC_SEED_DEFAULT_ROLES = 'MLFLOW_RBAC_SEED_DEFAULT_ROLES'
MLFLOW_READ_REPLICA_BACKEND_STORE_URI = 'MLFLOW_READ_REPLICA_BACKEND_S...
MLFLOW_RECORD_ENV_VARS_IN_MODEL_LOGGING = 'MLFLOW_RECORD_ENV_VARS_IN_M...
MLFLOW_REGISTRY_DIR = 'MLFLOW_REGISTRY_DIR'
MLFLOW_REGISTRY_URI = 'MLFLOW_REGISTRY_URI'
MLFLOW_REQUIREMENTS_INFERENCE_RAISE_ERRORS = 'MLFLOW_REQUIREMENTS_INFE...
MLFLOW_REQUIREMENTS_INFERENCE_TIMEOUT = 'MLFLOW_REQUIREMENTS_INFERENCE...
MLFLOW_RUN_CONTEXT = 'MLFLOW_RUN_CONTEXT'
MLFLOW_RUN_ID = 'MLFLOW_RUN_ID'
MLFLOW_S3_ENDPOINT_URL = 'MLFLOW_S3_ENDPOINT_URL'
MLFLOW_S3_EXPECTED_BUCKET_OWNER = 'MLFLOW_S3_EXPECTED_BUCKET_OWNER'
MLFLOW_S3_IGNORE_TLS = 'MLFLOW_S3_IGNORE_TLS'
MLFLOW_S3_UPLOAD_EXTRA_ARGS = 'MLFLOW_S3_UPLOAD_EXTRA_ARGS'
MLFLOW_SAGEMAKER_DEPLOY_IMG_URL = 'MLFLOW_SAGEMAKER_DEPLOY_IMG_URL'
MLFLOW_SCORING_SERVER_REQUEST_TIMEOUT = 'MLFLOW_SCORING_SERVER_REQUEST...
MLFLOW_SEARCH_TRACES_MAX_THREADS = 'MLFLOW_SEARCH_TRACES_MAX_THREADS'
MLFLOW_SERVER_ALLOWED_HOSTS = 'MLFLOW_SERVER_ALLOWED_HOSTS'
MLFLOW_SERVER_CORS_ALLOWED_ORIGINS = 'MLFLOW_SERVER_CORS_ALLOWED_ORIGI...
MLFLOW_SERVER_DISABLE_SECURITY_MIDDLEWARE = 'MLFLOW_SERVER_DISABLE_SEC...
MLFLOW_SERVER_ENABLE_GRAPHQL_AUTH = 'MLFLOW_SERVER_ENABLE_GRAPHQL_AUTH...
MLFLOW_SERVER_ENABLE_JOB_EXECUTION = 'MLFLOW_SERVER_ENABLE_JOB_EXECUTI...
MLFLOW_SERVER_GRAPHQL_MAX_ALIASES = 'MLFLOW_SERVER_GRAPHQL_MAX_ALIASES...
MLFLOW_SERVER_GRAPHQL_MAX_ROOT_FIELDS = 'MLFLOW_SERVER_GRAPHQL_MAX_ROO...
MLFLOW_SERVER_JOB_TRANSIENT_ERROR_MAX_RETRIES = 'MLFLOW_SERVER_JOB_TRA...
MLFLOW_SERVER_JOB_TRANSIENT_ERROR_RETRY_BASE_DELAY = 'MLFLOW_SERVER_JO...
MLFLOW_SERVER_JOB_TRANSIENT_ERROR_RETRY_MAX_DELAY = 'MLFLOW_SERVER_JOB...
MLFLOW_SERVER_JUDGE_INVOKE_MAX_WORKERS = 'MLFLOW_SERVER_JUDGE_INVOKE_M...
MLFLOW_SERVER_ONLINE_SCORING_MAX_WORKERS = 'MLFLOW_SERVER_ONLINE_SCORI...
MLFLOW_SERVER_SCORER_INVOKE_BATCH_SIZE = 'MLFLOW_SERVER_SCORER_INVOKE_...
MLFLOW_SERVER_X_FRAME_OPTIONS = 'MLFLOW_SERVER_X_FRAME_OPTIONS'
MLFLOW_SKIP_PIP_REQUIREMENTS_CHECK = 'MLFLOW_SKIP_PIP_REQUIREMENTS_CHE...
MLFLOW_SKIP_SIGNATURE_CHECK_FOR_UC_REGISTRY_MIGRATION = 'MLFLOW_SKIP_S...
MLFLOW_SQLALCHEMYSTORE_ECHO = 'MLFLOW_SQLALCHEMYSTORE_ECHO'
MLFLOW_SQLALCHEMYSTORE_MAX_OVERFLOW = 'MLFLOW_SQLALCHEMYSTORE_MAX_OVER...
MLFLOW_SQLALCHEMYSTORE_POOLCLASS = 'MLFLOW_SQLALCHEMYSTORE_POOLCLASS'
MLFLOW_SQLALCHEMYSTORE_POOL_RECYCLE = 'MLFLOW_SQLALCHEMYSTORE_POOL_REC...
MLFLOW_SQLALCHEMYSTORE_POOL_SIZE = 'MLFLOW_SQLALCHEMYSTORE_POOL_SIZE'
MLFLOW_SQL_WAREHOUSE_AUTO_START = 'MLFLOW_SQL_WAREHOUSE_AUTO_START'
MLFLOW_SQL_WAREHOUSE_AUTO_START_TIMEOUT_SECONDS = 'MLFLOW_SQL_WAREHOUS...
MLFLOW_SUPPRESS_PRINTING_URL_TO_STDOUT = 'MLFLOW_SUPPRESS_PRINTING_URL...
MLFLOW_SYSTEM_METRICS_NODE_ID = 'MLFLOW_SYSTEM_METRICS_NODE_ID'
MLFLOW_SYSTEM_METRICS_SAMPLES_BEFORE_LOGGING = 'MLFLOW_SYSTEM_METRICS_...
MLFLOW_SYSTEM_METRICS_SAMPLING_INTERVAL = 'MLFLOW_SYSTEM_METRICS_SAMPL...
MLFLOW_TRACE_ARCHIVAL_CONFIG = 'MLFLOW_TRACE_ARCHIVAL_CONFIG'
MLFLOW_TRACE_BUFFER_MAX_SIZE = 'MLFLOW_TRACE_BUFFER_MAX_SIZE'
MLFLOW_TRACE_BUFFER_TTL_SECONDS = 'MLFLOW_TRACE_BUFFER_TTL_SECONDS'
MLFLOW_TRACE_ENABLE_OTLP_DUAL_EXPORT = 'MLFLOW_TRACE_ENABLE_OTLP_DUAL_...
MLFLOW_TRACE_EXTRACT_ATTACHMENTS = 'MLFLOW_TRACE_EXTRACT_ATTACHMENTS'
MLFLOW_TRACE_MAX_ATTACHMENT_SIZE = 'MLFLOW_TRACE_MAX_ATTACHMENT_SIZE'
MLFLOW_TRACE_PROPAGATE_TO_OTEL_CONTEXT = 'MLFLOW_TRACE_PROPAGATE_TO_OT...
MLFLOW_TRACE_SAMPLING_RATIO = 'MLFLOW_TRACE_SAMPLING_RATIO'
MLFLOW_TRACE_TIMEOUT_CHECK_INTERVAL_SECONDS = 'MLFLOW_TRACE_TIMEOUT_CH...
MLFLOW_TRACE_TIMEOUT_SECONDS = 'MLFLOW_TRACE_TIMEOUT_SECONDS'
MLFLOW_TRACE_USE_ISOLATED_RANDOM_ID_GENERATOR = 'MLFLOW_TRACE_USE_ISOL...
MLFLOW_TRACING_DESTINATION = 'MLFLOW_TRACING_DESTINATION'
MLFLOW_TRACING_SQL_WAREHOUSE_ID = 'MLFLOW_TRACING_SQL_WAREHOUSE_ID'
MLFLOW_TRACKING_AUTH = 'MLFLOW_TRACKING_AUTH'
MLFLOW_TRACKING_AWS_SIGV4 = 'MLFLOW_TRACKING_AWS_SIGV4'
MLFLOW_TRACKING_CLIENT_CERT_PATH = 'MLFLOW_TRACKING_CLIENT_CERT_PATH'
MLFLOW_TRACKING_DIR = 'MLFLOW_TRACKING_DIR'
MLFLOW_TRACKING_INSECURE_TLS = 'MLFLOW_TRACKING_INSECURE_TLS'
MLFLOW_TRACKING_PASSWORD = 'MLFLOW_TRACKING_PASSWORD'
MLFLOW_TRACKING_SERVER_CERT_PATH = 'MLFLOW_TRACKING_SERVER_CERT_PATH'
MLFLOW_TRACKING_TOKEN = 'MLFLOW_TRACKING_TOKEN'
MLFLOW_TRACKING_URI = 'MLFLOW_TRACKING_URI'
MLFLOW_TRACKING_USERNAME = 'MLFLOW_TRACKING_USERNAME'
MLFLOW_TRUNCATE_LONG_VALUES = 'MLFLOW_TRUNCATE_LONG_VALUES'
MLFLOW_UC_OSS_TOKEN = 'MLFLOW_UC_OSS_TOKEN'
MLFLOW_USE_BATCH_SPAN_PROCESSOR = 'MLFLOW_USE_BATCH_SPAN_PROCESSOR'
MLFLOW_USE_DATABRICKS_SDK_MODEL_ARTIFACTS_REPO_FOR_UC = 'MLFLOW_USE_DA...
MLFLOW_USE_DEFAULT_TRACER_PROVIDER = 'MLFLOW_USE_DEFAULT_TRACER_PROVID...
MLFLOW_UV_AUTO_DETECT = 'MLFLOW_UV_AUTO_DETECT'
MLFLOW_VERSION_PROMPT_CACHE_TTL_SECONDS = 'MLFLOW_VERSION_PROMPT_CACHE...
MLFLOW_WEBHOOK_CACHE_TTL = 'MLFLOW_WEBHOOK_CACHE_TTL'
MLFLOW_WEBHOOK_DELIVERY_MAX_WORKERS = 'MLFLOW_WEBHOOK_DELIVERY_MAX_WOR...
MLFLOW_WEBHOOK_REQUEST_MAX_RETRIES = 'MLFLOW_WEBHOOK_REQUEST_MAX_RETRI...
MLFLOW_WEBHOOK_REQUEST_TIMEOUT = 'MLFLOW_WEBHOOK_REQUEST_TIMEOUT'
MLFLOW_WEBHOOK_SECRET_ENCRYPTION_KEY = 'MLFLOW_WEBHOOK_SECRET_ENCRYPTI...
MLFLOW_WHEELED_MODEL_PIP_DOWNLOAD_OPTIONS = 'MLFLOW_WHEELED_MODEL_PIP_...
MLFLOW_WORKSPACE = 'MLFLOW_WORKSPACE'
MLFLOW_WORKSPACE_ARTIFACT_ROOT_CACHE_CAPACITY = 'MLFLOW_WORKSPACE_ARTI...
MLFLOW_WORKSPACE_ARTIFACT_ROOT_CACHE_TTL_SECONDS = 'MLFLOW_WORKSPACE_A...
MLFLOW_WORKSPACE_STORE_URI = 'MLFLOW_WORKSPACE_STORE_URI'
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\environment_variables.py
mlflow.error_classification
Python Library Documentation: module mlflow.error_classification in mlflow
NAME
mlflow.error_classification - Centralized error classification for MLflow exceptions.
DESCRIPTION
Maps error codes to sqlstate codes and error classes for structured error
classification and observability. Client-side errors use the KAM0x/XXM0x
namespace, while server/CP errors use the KAMCx/XXMCx namespace.
Terminology:
error_code: The existing MLflow error code from the protobuf definition
(e.g., INVALID_PARAMETER_VALUE, INTERNAL_ERROR). Defined in
mlflow/protos/databricks.proto. These are coarse-grained — many
different failure modes share the same error_code.
error_class: A more specific classification of the error (e.g.,
SCHEMA_ENFORCEMENT_FAILED, ATTRIBUTE_NOT_FOUND). Defined in the
ErrorClass enum below. When an error_class is not explicitly set
at a raise site, it is auto-derived from the error_code.
sqlstate: A 5-character code used by reliability dashboards to
categorize errors (e.g., KAM01, XXMC0). Defined in the SqlState
enum below. Derived automatically from error_class (if a specific
mapping exists) or from error_code (generic fallback).
Derivation chain in MlflowException.__init__:
1. error_class: explicit value if provided, otherwise derived from error_code
2. sqlstate: explicit value if provided, otherwise derived from error_class
(via _ERROR_CLASS_TO_SQLSTATE), otherwise derived from error_code
(via _CLIENT_ERROR_CODE_TO_SQLSTATE)
When to override at a raise site:
Most raise sites do NOT need to pass sqlstate or error_class — both are
auto-derived from error_code. Only pass error_class when the error_code
is too coarse to distinguish the specific failure. For example,
INVALID_PARAMETER_VALUE is used for both schema enforcement failures and
attribute lookup failures, so those raise sites pass error_class to
get distinct sqlstate codes (KAM01 vs KAM04). Never pass sqlstate
directly — it is always derived from error_class.
CLASSES
builtins.str(builtins.object)
ErrorClass(builtins.str, enum.Enum)
SqlState(builtins.str, enum.Enum)
enum.Enum(builtins.object)
ErrorClass(builtins.str, enum.Enum)
SqlState(builtins.str, enum.Enum)
class ErrorClass(builtins.str, enum.Enum)
| ErrorClass(*values)
|
| Error class names for MLflow error classification.
|
| Method resolution order:
| ErrorClass
| builtins.str
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec) from enum.Enum
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__(self) from enum.Enum
| Return str(self).
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| ATTRIBUTE_NOT_FOUND = <ErrorClass.ATTRIBUTE_NOT_FOUND: 'ATTRIBUTE_NOT_...
|
| CLIENT_INTERNAL_ERROR = <ErrorClass.CLIENT_INTERNAL_ERROR: 'CLIENT_INT...
|
| CP_INTERNAL_ERROR = <ErrorClass.CP_INTERNAL_ERROR: 'CP_INTERNAL_ERROR'...
|
| CP_INVALID_PARAMETER_VALUE = <ErrorClass.CP_INVALID_PARAMETER_VALUE: '...
|
| CP_INVALID_STATE = <ErrorClass.CP_INVALID_STATE: 'CP_INVALID_STATE'>
|
| CP_PERMISSION_DENIED = <ErrorClass.CP_PERMISSION_DENIED: 'CP_PERMISSIO...
|
| CP_REQUEST_RATE_LIMITED = <ErrorClass.CP_REQUEST_RATE_LIMITED: 'CP_REQ...
|
| CP_RESOURCE_CONFLICT = <ErrorClass.CP_RESOURCE_CONFLICT: 'CP_RESOURCE_...
|
| CP_RESOURCE_NOT_FOUND = <ErrorClass.CP_RESOURCE_NOT_FOUND: 'CP_RESOURC...
|
| CP_TEMPORARILY_UNAVAILABLE = <ErrorClass.CP_TEMPORARILY_UNAVAILABLE: '...
|
| FEATURE_DISABLED = <ErrorClass.FEATURE_DISABLED: 'FEATURE_DISABLED'>
|
| INVALID_PARAMETER_VALUE = <ErrorClass.INVALID_PARAMETER_VALUE: 'INVALI...
|
| MODEL_SERIALIZATION_FAILED = <ErrorClass.MODEL_SERIALIZATION_FAILED: '...
|
| PERMISSION_DENIED = <ErrorClass.PERMISSION_DENIED: 'PERMISSION_DENIED'...
|
| PREDICTION_FUNCTION_FAILED = <ErrorClass.PREDICTION_FUNCTION_FAILED: '...
|
| RESOURCE_ALREADY_EXISTS = <ErrorClass.RESOURCE_ALREADY_EXISTS: 'RESOUR...
|
| RESOURCE_NOT_FOUND = <ErrorClass.RESOURCE_NOT_FOUND: 'RESOURCE_NOT_FOU...
|
| SCHEMA_ENFORCEMENT_FAILED = <ErrorClass.SCHEMA_ENFORCEMENT_FAILED: 'SC...
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.str:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(...)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __sizeof__(self, /)
| Return the size of the string in memory, in bytes.
|
| capitalize(self, /)
| Return a capitalized version of the string.
|
| More specifically, make the first character have upper case and the rest lower
| case.
|
| casefold(self, /)
| Return a version of the string suitable for caseless comparisons.
|
| center(self, width, fillchar=' ', /)
| Return a centered string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| count(...)
| S.count(sub[, start[, end]]) -> int
|
| Return the number of non-overlapping occurrences of substring sub in
| string S[start:end]. Optional arguments start and end are
| interpreted as in slice notation.
|
| encode(self, /, encoding='utf-8', errors='strict')
| Encode the string using the codec registered for encoding.
|
| encoding
| The encoding in which to encode the string.
| errors
| The error handling scheme to use for encoding errors.
| The default is 'strict' meaning that encoding errors raise a
| UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
| 'xmlcharrefreplace' as well as any other name registered with
| codecs.register_error that can handle UnicodeEncodeErrors.
|
| endswith(...)
| S.endswith(suffix[, start[, end]]) -> bool
|
| Return True if S ends with the specified suffix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| suffix can also be a tuple of strings to try.
|
| expandtabs(self, /, tabsize=8)
| Return a copy where all tab characters are expanded using spaces.
|
| If tabsize is not given, a tab size of 8 characters is assumed.
|
| find(...)
| S.find(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| format(...)
| S.format(*args, **kwargs) -> str
|
| Return a formatted version of S, using substitutions from args and kwargs.
| The substitutions are identified by braces ('{' and '}').
|
| format_map(...)
| S.format_map(mapping) -> str
|
| Return a formatted version of S, using substitutions from mapping.
| The substitutions are identified by braces ('{' and '}').
|
| index(...)
| S.index(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| isalnum(self, /)
| Return True if the string is an alpha-numeric string, False otherwise.
|
| A string is alpha-numeric if all characters in the string are alpha-numeric and
| there is at least one character in the string.
|
| isalpha(self, /)
| Return True if the string is an alphabetic string, False otherwise.
|
| A string is alphabetic if all characters in the string are alphabetic and there
| is at least one character in the string.
|
| isascii(self, /)
| Return True if all characters in the string are ASCII, False otherwise.
|
| ASCII characters have code points in the range U+0000-U+007F.
| Empty string is ASCII too.
|
| isdecimal(self, /)
| Return True if the string is a decimal string, False otherwise.
|
| A string is a decimal string if all characters in the string are decimal and
| there is at least one character in the string.
|
| isdigit(self, /)
| Return True if the string is a digit string, False otherwise.
|
| A string is a digit string if all characters in the string are digits and there
| is at least one character in the string.
|
| isidentifier(self, /)
| Return True if the string is a valid Python identifier, False otherwise.
|
| Call keyword.iskeyword(s) to test whether string s is a reserved identifier,
| such as "def" or "class".
|
| islower(self, /)
| Return True if the string is a lowercase string, False otherwise.
|
| A string is lowercase if all cased characters in the string are lowercase and
| there is at least one cased character in the string.
|
| isnumeric(self, /)
| Return True if the string is a numeric string, False otherwise.
|
| A string is numeric if all characters in the string are numeric and there is at
| least one character in the string.
|
| isprintable(self, /)
| Return True if the string is printable, False otherwise.
|
| A string is printable if all of its characters are considered printable in
| repr() or if it is empty.
|
| isspace(self, /)
| Return True if the string is a whitespace string, False otherwise.
|
| A string is whitespace if all characters in the string are whitespace and there
| is at least one character in the string.
|
| istitle(self, /)
| Return True if the string is a title-cased string, False otherwise.
|
| In a title-cased string, upper- and title-case characters may only
| follow uncased characters and lowercase characters only cased ones.
|
| isupper(self, /)
| Return True if the string is an uppercase string, False otherwise.
|
| A string is uppercase if all cased characters in the string are uppercase and
| there is at least one cased character in the string.
|
| join(self, iterable, /)
| Concatenate any number of strings.
|
| The string whose method is called is inserted in between each given string.
| The result is returned as a new string.
|
| Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
|
| ljust(self, width, fillchar=' ', /)
| Return a left-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| lower(self, /)
| Return a copy of the string converted to lowercase.
|
| lstrip(self, chars=None, /)
| Return a copy of the string with leading whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| partition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string. If the separator is found,
| returns a 3-tuple containing the part before the separator, the separator
| itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing the original string
| and two empty strings.
|
| removeprefix(self, prefix, /)
| Return a str with the given prefix string removed if present.
|
| If the string starts with the prefix string, return string[len(prefix):].
| Otherwise, return a copy of the original string.
|
| removesuffix(self, suffix, /)
| Return a str with the given suffix string removed if present.
|
| If the string ends with the suffix string and that suffix is not empty,
| return string[:-len(suffix)]. Otherwise, return a copy of the original
| string.
|
| replace(self, old, new, count=-1, /)
| Return a copy with all occurrences of substring old replaced by new.
|
| count
| Maximum number of occurrences to replace.
| -1 (the default value) means replace all occurrences.
|
| If the optional argument count is given, only the first count occurrences are
| replaced.
|
| rfind(...)
| S.rfind(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| rindex(...)
| S.rindex(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| rjust(self, width, fillchar=' ', /)
| Return a right-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| rpartition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string, starting at the end. If
| the separator is found, returns a 3-tuple containing the part before the
| separator, the separator itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing two empty strings
| and the original string.
|
| rsplit(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the end of the string and works to the front.
|
| rstrip(self, chars=None, /)
| Return a copy of the string with trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| split(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the front of the string and works to the end.
|
| Note, str.split() is mainly useful for data that has been intentionally
| delimited. With natural text that includes punctuation, consider using
| the regular expression module.
|
| splitlines(self, /, keepends=False)
| Return a list of the lines in the string, breaking at line boundaries.
|
| Line breaks are not included in the resulting list unless keepends is given and
| true.
|
| startswith(...)
| S.startswith(prefix[, start[, end]]) -> bool
|
| Return True if S starts with the specified prefix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| prefix can also be a tuple of strings to try.
|
| strip(self, chars=None, /)
| Return a copy of the string with leading and trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| swapcase(self, /)
| Convert uppercase characters to lowercase and lowercase characters to uppercase.
|
| title(self, /)
| Return a version of the string where each word is titlecased.
|
| More specifically, words start with uppercased characters and all remaining
| cased characters have lower case.
|
| translate(self, table, /)
| Replace each character in the string using the given translation table.
|
| table
| Translation table, which must be a mapping of Unicode ordinals to
| Unicode ordinals, strings, or None.
|
| The table must implement lookup/indexing via __getitem__, for instance a
| dictionary or list. If this operation raises LookupError, the character is
| left untouched. Characters mapped to None are deleted.
|
| upper(self, /)
| Return a copy of the string converted to uppercase.
|
| zfill(self, width, /)
| Pad a numeric string with zeros on the left, to fill a field of the given width.
|
| The string is never truncated.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.str:
|
| maketrans(...)
| Return a translation table usable for str.translate().
|
| If there is only one argument, it must be a dictionary mapping Unicode
| ordinals (integers) or characters to Unicode ordinals, strings or None.
| Character keys will be then converted to ordinals.
| If there are two arguments, they must be strings of equal length, and
| in the resulting dictionary, each character in x will be mapped to the
| character at the same position in y. If there is a third argument, it
| must be a string, whose characters will be mapped to None in the result.
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class SqlState(builtins.str, enum.Enum)
| SqlState(*values)
|
| SQLSTATE codes for MLflow error classification.
|
| Method resolution order:
| SqlState
| builtins.str
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec) from enum.Enum
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__(self) from enum.Enum
| Return str(self).
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| CLIENT_ATTRIBUTE_NOT_FOUND = <SqlState.CLIENT_ATTRIBUTE_NOT_FOUND: 'KA...
|
| CLIENT_INTERNAL_ERROR = <SqlState.CLIENT_INTERNAL_ERROR: 'XXM00'>
|
| CLIENT_INVALID_PARAMETER = <SqlState.CLIENT_INVALID_PARAMETER: 'KAM00'...
|
| CLIENT_MODEL_SERIALIZATION_FAILED = <SqlState.CLIENT_MODEL_SERIALIZATI...
|
| CLIENT_PREDICTION_FUNCTION_FAILED = <SqlState.CLIENT_PREDICTION_FUNCTI...
|
| CLIENT_SCHEMA_ENFORCEMENT_FAILED = <SqlState.CLIENT_SCHEMA_ENFORCEMENT...
|
| CP_INTERNAL_ERROR = <SqlState.CP_INTERNAL_ERROR: 'XXMC0'>
|
| CP_INVALID_PARAMETER = <SqlState.CP_INVALID_PARAMETER: 'KAMC4'>
|
| CP_INVALID_STATE = <SqlState.CP_INVALID_STATE: 'XXMC2'>
|
| CP_PERMISSION_DENIED = <SqlState.CP_PERMISSION_DENIED: 'KAMC1'>
|
| CP_REQUEST_RATE_LIMITED = <SqlState.CP_REQUEST_RATE_LIMITED: 'KAMC3'>
|
| CP_RESOURCE_CONFLICT = <SqlState.CP_RESOURCE_CONFLICT: 'KAMC5'>
|
| CP_RESOURCE_NOT_FOUND = <SqlState.CP_RESOURCE_NOT_FOUND: 'KAMC2'>
|
| CP_TEMPORARILY_UNAVAILABLE = <SqlState.CP_TEMPORARILY_UNAVAILABLE: 'XX...
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.str:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(...)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __sizeof__(self, /)
| Return the size of the string in memory, in bytes.
|
| capitalize(self, /)
| Return a capitalized version of the string.
|
| More specifically, make the first character have upper case and the rest lower
| case.
|
| casefold(self, /)
| Return a version of the string suitable for caseless comparisons.
|
| center(self, width, fillchar=' ', /)
| Return a centered string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| count(...)
| S.count(sub[, start[, end]]) -> int
|
| Return the number of non-overlapping occurrences of substring sub in
| string S[start:end]. Optional arguments start and end are
| interpreted as in slice notation.
|
| encode(self, /, encoding='utf-8', errors='strict')
| Encode the string using the codec registered for encoding.
|
| encoding
| The encoding in which to encode the string.
| errors
| The error handling scheme to use for encoding errors.
| The default is 'strict' meaning that encoding errors raise a
| UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
| 'xmlcharrefreplace' as well as any other name registered with
| codecs.register_error that can handle UnicodeEncodeErrors.
|
| endswith(...)
| S.endswith(suffix[, start[, end]]) -> bool
|
| Return True if S ends with the specified suffix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| suffix can also be a tuple of strings to try.
|
| expandtabs(self, /, tabsize=8)
| Return a copy where all tab characters are expanded using spaces.
|
| If tabsize is not given, a tab size of 8 characters is assumed.
|
| find(...)
| S.find(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| format(...)
| S.format(*args, **kwargs) -> str
|
| Return a formatted version of S, using substitutions from args and kwargs.
| The substitutions are identified by braces ('{' and '}').
|
| format_map(...)
| S.format_map(mapping) -> str
|
| Return a formatted version of S, using substitutions from mapping.
| The substitutions are identified by braces ('{' and '}').
|
| index(...)
| S.index(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| isalnum(self, /)
| Return True if the string is an alpha-numeric string, False otherwise.
|
| A string is alpha-numeric if all characters in the string are alpha-numeric and
| there is at least one character in the string.
|
| isalpha(self, /)
| Return True if the string is an alphabetic string, False otherwise.
|
| A string is alphabetic if all characters in the string are alphabetic and there
| is at least one character in the string.
|
| isascii(self, /)
| Return True if all characters in the string are ASCII, False otherwise.
|
| ASCII characters have code points in the range U+0000-U+007F.
| Empty string is ASCII too.
|
| isdecimal(self, /)
| Return True if the string is a decimal string, False otherwise.
|
| A string is a decimal string if all characters in the string are decimal and
| there is at least one character in the string.
|
| isdigit(self, /)
| Return True if the string is a digit string, False otherwise.
|
| A string is a digit string if all characters in the string are digits and there
| is at least one character in the string.
|
| isidentifier(self, /)
| Return True if the string is a valid Python identifier, False otherwise.
|
| Call keyword.iskeyword(s) to test whether string s is a reserved identifier,
| such as "def" or "class".
|
| islower(self, /)
| Return True if the string is a lowercase string, False otherwise.
|
| A string is lowercase if all cased characters in the string are lowercase and
| there is at least one cased character in the string.
|
| isnumeric(self, /)
| Return True if the string is a numeric string, False otherwise.
|
| A string is numeric if all characters in the string are numeric and there is at
| least one character in the string.
|
| isprintable(self, /)
| Return True if the string is printable, False otherwise.
|
| A string is printable if all of its characters are considered printable in
| repr() or if it is empty.
|
| isspace(self, /)
| Return True if the string is a whitespace string, False otherwise.
|
| A string is whitespace if all characters in the string are whitespace and there
| is at least one character in the string.
|
| istitle(self, /)
| Return True if the string is a title-cased string, False otherwise.
|
| In a title-cased string, upper- and title-case characters may only
| follow uncased characters and lowercase characters only cased ones.
|
| isupper(self, /)
| Return True if the string is an uppercase string, False otherwise.
|
| A string is uppercase if all cased characters in the string are uppercase and
| there is at least one cased character in the string.
|
| join(self, iterable, /)
| Concatenate any number of strings.
|
| The string whose method is called is inserted in between each given string.
| The result is returned as a new string.
|
| Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
|
| ljust(self, width, fillchar=' ', /)
| Return a left-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| lower(self, /)
| Return a copy of the string converted to lowercase.
|
| lstrip(self, chars=None, /)
| Return a copy of the string with leading whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| partition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string. If the separator is found,
| returns a 3-tuple containing the part before the separator, the separator
| itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing the original string
| and two empty strings.
|
| removeprefix(self, prefix, /)
| Return a str with the given prefix string removed if present.
|
| If the string starts with the prefix string, return string[len(prefix):].
| Otherwise, return a copy of the original string.
|
| removesuffix(self, suffix, /)
| Return a str with the given suffix string removed if present.
|
| If the string ends with the suffix string and that suffix is not empty,
| return string[:-len(suffix)]. Otherwise, return a copy of the original
| string.
|
| replace(self, old, new, count=-1, /)
| Return a copy with all occurrences of substring old replaced by new.
|
| count
| Maximum number of occurrences to replace.
| -1 (the default value) means replace all occurrences.
|
| If the optional argument count is given, only the first count occurrences are
| replaced.
|
| rfind(...)
| S.rfind(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| rindex(...)
| S.rindex(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| rjust(self, width, fillchar=' ', /)
| Return a right-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| rpartition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string, starting at the end. If
| the separator is found, returns a 3-tuple containing the part before the
| separator, the separator itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing two empty strings
| and the original string.
|
| rsplit(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the end of the string and works to the front.
|
| rstrip(self, chars=None, /)
| Return a copy of the string with trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| split(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the front of the string and works to the end.
|
| Note, str.split() is mainly useful for data that has been intentionally
| delimited. With natural text that includes punctuation, consider using
| the regular expression module.
|
| splitlines(self, /, keepends=False)
| Return a list of the lines in the string, breaking at line boundaries.
|
| Line breaks are not included in the resulting list unless keepends is given and
| true.
|
| startswith(...)
| S.startswith(prefix[, start[, end]]) -> bool
|
| Return True if S starts with the specified prefix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| prefix can also be a tuple of strings to try.
|
| strip(self, chars=None, /)
| Return a copy of the string with leading and trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| swapcase(self, /)
| Convert uppercase characters to lowercase and lowercase characters to uppercase.
|
| title(self, /)
| Return a version of the string where each word is titlecased.
|
| More specifically, words start with uppercased characters and all remaining
| cased characters have lower case.
|
| translate(self, table, /)
| Replace each character in the string using the given translation table.
|
| table
| Translation table, which must be a mapping of Unicode ordinals to
| Unicode ordinals, strings, or None.
|
| The table must implement lookup/indexing via __getitem__, for instance a
| dictionary or list. If this operation raises LookupError, the character is
| left untouched. Characters mapped to None are deleted.
|
| upper(self, /)
| Return a copy of the string converted to uppercase.
|
| zfill(self, width, /)
| Pad a numeric string with zeros on the left, to fill a field of the given width.
|
| The string is never truncated.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.str:
|
| maketrans(...)
| Return a translation table usable for str.translate().
|
| If there is only one argument, it must be a dictionary mapping Unicode
| ordinals (integers) or characters to Unicode ordinals, strings or None.
| Character keys will be then converted to ordinals.
| If there are two arguments, they must be strings of equal length, and
| in the resulting dictionary, each character in x will be mapped to the
| character at the same position in y. If there is a third argument, it
| must be a string, whose characters will be mapped to None in the result.
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
DATA
__annotations__ = {'_CLIENT_ERROR_CODE_TO_ERROR_CLASS': 'dict[str, Err...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\error_classification.py
mlflow.evaluate
Python Library Documentation: function evaluate in module mlflow.models.evaluation.base
evaluate(model=None, data=None, *, model_type=None, targets=None, predictions=None, dataset_path=None, feature_names=None, evaluators=None, evaluator_config=None, extra_metrics=None, custom_artifacts=None, env_manager='local', model_config=None, inference_params=None, model_id=None, _called_from_genai_evaluate=False)
Evaluate the model performance on given data and selected metrics.
This function evaluates a PyFunc model or custom callable on the specified dataset using
specified ``evaluators``, and logs resulting metrics & artifacts to MLflow tracking server.
Users can also skip setting ``model`` and put the model outputs in ``data`` directly for
evaluation. For detailed information, please read
`the Model Evaluation documentation <../../model-evaluation/index.html>`_.
Default Evaluator behavior:
- The default evaluator, which can be invoked with ``evaluators="default"`` or
``evaluators=None``, supports model types listed below. For each pre-defined model type, the
default evaluator evaluates your model on a selected set of metrics and generate artifacts
like plots. Please find more details below.
- For both the ``"regressor"`` and ``"classifier"`` model types, the default evaluator
generates model summary plots and feature importance plots using
`SHAP <https://shap.readthedocs.io/en/latest/index.html>`_.
- For regressor models, the default evaluator additionally logs:
- **metrics**: example_count, mean_absolute_error, mean_squared_error,
root_mean_squared_error, sum_on_target, mean_on_target, r2_score, max_error,
mean_absolute_percentage_error.
- For binary classifiers, the default evaluator additionally logs:
- **metrics**: true_negatives, false_positives, false_negatives, true_positives, recall,
precision, f1_score, accuracy_score, example_count, log_loss, roc_auc,
precision_recall_auc.
- **artifacts**: lift curve plot, precision-recall plot, ROC plot.
- For multiclass classifiers, the default evaluator additionally logs:
- **metrics**: accuracy_score, example_count, f1_score_micro, f1_score_macro, log_loss
- **artifacts**: A CSV file for "per_class_metrics" (per-class metrics includes
true_negatives/false_positives/false_negatives/true_positives/recall/precision/roc_auc,
precision_recall_auc), precision-recall merged curves plot, ROC merged curves plot.
- For question-answering models, the default evaluator logs:
- **metrics**: ``exact_match``, ``token_count``, `toxicity`_ (requires `evaluate`_,
`torch`_, `flesch_kincaid_grade_level`_ (requires `textstat`_) and `ari_grade_level`_.
- **artifacts**: A JSON file containing the inputs, outputs, targets (if the ``targets``
argument is supplied), and per-row metrics of the model in tabular format.
.. _toxicity:
https://huggingface.co/spaces/evaluate-measurement/toxicity
.. _torch:
https://pytorch.org/get-started/locally/
.. _transformers:
https://huggingface.co/docs/transformers/installation
.. _ari_grade_level:
https://en.wikipedia.org/wiki/Automated_readability_index
.. _flesch_kincaid_grade_level:
https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests#Flesch%E2%80%93Kincaid_grade_level
.. _evaluate:
https://pypi.org/project/evaluate
.. _textstat:
https://pypi.org/project/textstat
- For text-summarization models, the default evaluator logs:
- **metrics**: ``token_count``, `ROUGE`_ (requires `evaluate`_, `nltk`_, and
`rouge_score`_ to be installed), `toxicity`_ (requires `evaluate`_, `torch`_,
`transformers`_), `ari_grade_level`_ (requires `textstat`_),
`flesch_kincaid_grade_level`_ (requires `textstat`_).
- **artifacts**: A JSON file containing the inputs, outputs, targets (if the ``targets``
argument is supplied), and per-row metrics of the model in the tabular format.
.. _ROUGE:
https://huggingface.co/spaces/evaluate-metric/rouge
.. _toxicity:
https://huggingface.co/spaces/evaluate-measurement/toxicity
.. _torch:
https://pytorch.org/get-started/locally/
.. _transformers:
https://huggingface.co/docs/transformers/installation
.. _ari_grade_level:
https://en.wikipedia.org/wiki/Automated_readability_index
.. _flesch_kincaid_grade_level:
https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests#Flesch%E2%80%93Kincaid_grade_level
.. _evaluate:
https://pypi.org/project/evaluate
.. _nltk:
https://pypi.org/project/nltk
.. _rouge_score:
https://pypi.org/project/rouge-score
.. _textstat:
https://pypi.org/project/textstat
- For text models, the default evaluator logs:
- **metrics**: ``token_count``, `toxicity`_ (requires `evaluate`_, `torch`_,
`transformers`_), `ari_grade_level`_ (requires `textstat`_),
`flesch_kincaid_grade_level`_ (requires `textstat`_).
- **artifacts**: A JSON file containing the inputs, outputs, targets (if the ``targets``
argument is supplied), and per-row metrics of the model in tabular format.
.. _evaluate:
https://pypi.org/project/evaluate
.. _toxicity:
https://huggingface.co/spaces/evaluate-measurement/toxicity
.. _torch:
https://pytorch.org/get-started/locally/
.. _transformers:
https://huggingface.co/docs/transformers/installation
.. _ari_grade_level:
https://en.wikipedia.org/wiki/Automated_readability_index
.. _flesch_kincaid_grade_level:
https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests#Flesch%E2%80%93Kincaid_grade_level
.. _textstat:
https://pypi.org/project/textstat
- For retriever models, the default evaluator logs:
- **metrics**: :mod:`precision_at_k(k) <mlflow.metrics.precision_at_k>`,
:mod:`recall_at_k(k) <mlflow.metrics.recall_at_k>` and
:mod:`ndcg_at_k(k) <mlflow.metrics.ndcg_at_k>` - all have a default value of
``retriever_k`` = 3.
- **artifacts**: A JSON file containing the inputs, outputs, targets, and per-row metrics
of the model in tabular format.
- For sklearn models, the default evaluator additionally logs the model's evaluation criterion
(e.g. mean accuracy for a classifier) computed by `model.score` method.
- The metrics/artifacts listed above are logged to the active MLflow run.
If no active run exists, a new MLflow run is created for logging these metrics and
artifacts.
- Additionally, information about the specified dataset - hash, name (if specified), path
(if specified), and the UUID of the model that evaluated it - is logged to the
``mlflow.datasets`` tag.
- The available ``evaluator_config`` options for the default evaluator include:
- **log_model_explainability**: A boolean value specifying whether or not to log model
explainability insights, default value is True.
- **log_explainer**: If True, log the explainer used to compute model explainability
insights as a model. Default value is False.
- **explainability_algorithm**: A string to specify the SHAP Explainer algorithm for model
explainability. Supported algorithm includes: 'exact', 'permutation', 'partition',
'kernel'.
If not set, ``shap.Explainer`` is used with the "auto" algorithm, which chooses the best
Explainer based on the model.
- **explainability_nsamples**: The number of sample rows to use for computing model
explainability insights. Default value is 2000.
- **explainability_kernel_link**: The kernel link function used by shap kernel explainer.
Available values are "identity" and "logit". Default value is "identity".
- **max_classes_for_multiclass_roc_pr**:
For multiclass classification tasks, the maximum number of classes for which to log
the per-class ROC curve and Precision-Recall curve. If the number of classes is
larger than the configured maximum, these curves are not logged.
- **metric_prefix**: An optional prefix to prepend to the name of each metric and artifact
produced during evaluation.
- **log_metrics_with_dataset_info**: A boolean value specifying whether or not to include
information about the evaluation dataset in the name of each metric logged to MLflow
Tracking during evaluation, default value is True.
- **pos_label**: If specified, the positive label to use when computing classification
metrics such as precision, recall, f1, etc. for binary classification models. For
multiclass classification and regression models, this parameter will be ignored.
- **average**: The averaging method to use when computing classification metrics such as
precision, recall, f1, etc. for multiclass classification models
(default: ``'weighted'``). For binary classification and regression models, this
parameter will be ignored.
- **sample_weights**: Weights for each sample to apply when computing model performance
metrics.
- **col_mapping**: A dictionary mapping column names in the input dataset or output
predictions to column names used when invoking the evaluation functions.
- **retriever_k**: A parameter used when ``model_type="retriever"`` as the number of
top-ranked retrieved documents to use when computing the built-in metric
:mod:`precision_at_k(k) <mlflow.metrics.precision_at_k>`,
:mod:`recall_at_k(k) <mlflow.metrics.recall_at_k>` and
:mod:`ndcg_at_k(k) <mlflow.metrics.ndcg_at_k>`. Default value is 3. For all other
model types, this parameter will be ignored.
- Limitations of evaluation dataset:
- For classification tasks, dataset labels are used to infer the total number of classes.
- For binary classification tasks, the negative label value must be 0 or -1 or False, and
the positive label value must be 1 or True.
- Limitations of metrics/artifacts computation:
- For classification tasks, some metric and artifact computations require the model to
output class probabilities. Currently, for scikit-learn models, the default evaluator
calls the ``predict_proba`` method on the underlying model to obtain probabilities. For
other model types, the default evaluator does not compute metrics/artifacts that require
probability outputs.
- Limitations of default evaluator logging model explainability insights:
- The ``shap.Explainer`` ``auto`` algorithm uses the ``Linear`` explainer for linear models
and the ``Tree`` explainer for tree models. Because SHAP's ``Linear`` and ``Tree``
explainers do not support multi-class classification, the default evaluator falls back to
using the ``Exact`` or ``Permutation`` explainers for multi-class classification tasks.
- Logging model explainability insights is not currently supported for PySpark models.
- The evaluation dataset label values must be numeric or boolean, all feature values
must be numeric, and each feature column must only contain scalar values.
- Limitations when environment restoration is enabled:
- When environment restoration is enabled for the evaluated model (i.e. a non-local
``env_manager`` is specified), the model is loaded as a client that invokes a MLflow
Model Scoring Server process in an independent Python environment with the model's
training time dependencies installed. As such, methods like ``predict_proba`` (for
probability outputs) or ``score`` (computes the evaluation criterian for sklearn models)
of the model become inaccessible and the default evaluator does not compute metrics or
artifacts that require those methods.
- Because the model is an MLflow Model Server process, SHAP explanations are slower to
compute. As such, model explainaibility is disabled when a non-local ``env_manager``
specified, unless the ``evaluator_config`` option **log_model_explainability** is
explicitly set to ``True``.
Args:
model: Optional. If specified, it should be one of the following:
- A pyfunc model instance
- A URI referring to a pyfunc model
- A URI referring to an MLflow Deployments endpoint e.g. ``"endpoints:/my-chat"``
- A callable function: This function should be able to take in model input and
return predictions. It should follow the signature of the
:py:func:`predict <mlflow.pyfunc.PyFuncModel.predict>` method. Here's an example
of a valid function:
.. code-block:: python
model = mlflow.pyfunc.load_model(model_uri)
def fn(model_input):
return model.predict(model_input)
If omitted, it indicates a static dataset will be used for evaluation instead of a
model. In this case, the ``data`` argument must be a Pandas DataFrame or an mlflow
PandasDataset that contains model outputs, and the ``predictions`` argument must be the
name of the column in ``data`` that contains model outputs.
data: One of the
following:
- A numpy array or list of evaluation features, excluding labels.
- A Pandas DataFrame containing evaluation features, labels, and optionally model
outputs. Model outputs are required to be provided when model is unspecified.
If ``feature_names`` argument not specified, all columns except for the label
column and predictions column are regarded as feature columns. Otherwise,
only column names present in ``feature_names`` are regarded as feature columns.
- A Spark DataFrame containing evaluation features and labels. If
``feature_names`` argument not specified, all columns except for the label
column are regarded as feature columns. Otherwise, only column names present in
``feature_names`` are regarded as feature columns. Only the first 10000 rows in
the Spark DataFrame will be used as evaluation data.
- A :py:class:`mlflow.data.dataset.Dataset` instance containing evaluation
features, labels, and optionally model outputs. Model outputs are only supported
with a PandasDataset. Model outputs are required when model is unspecified, and
should be specified via the ``predictions`` property of the PandasDataset.
model_type: (Optional) A string describing the model type. The default evaluator
supports the following model types:
- ``'classifier'``
- ``'regressor'``
- ``'question-answering'``
- ``'text-summarization'``
- ``'text'``
- ``'retriever'``
If no ``model_type`` is specified, then you must provide a list of
metrics to compute via the ``extra_metrics`` param.
.. note::
``'question-answering'``, ``'text-summarization'``, ``'text'``, and
``'retriever'`` are experimental and may be changed or removed in a
future release.
targets: If ``data`` is a numpy array or list, a numpy array or list of evaluation
labels. If ``data`` is a DataFrame, the string name of a column from ``data``
that contains evaluation labels. Required for classifier and regressor models,
but optional for question-answering, text-summarization, and text models. If
``data`` is a :py:class:`mlflow.data.dataset.Dataset` that defines targets,
then ``targets`` is optional.
predictions: Optional. The name of the column that contains model outputs.
- When ``model`` is specified and outputs multiple columns, ``predictions`` can be used
to specify the name of the column that will be used to store model outputs for
evaluation.
- When ``model`` is not specified and ``data`` is a pandas dataframe,
``predictions`` can be used to specify the name of the column in ``data`` that
contains model outputs.
.. code-block:: python
:caption: Example usage of predictions
# Evaluate a model that outputs multiple columns
data = pd.DataFrame({"question": ["foo"]})
def model(inputs):
return pd.DataFrame({"answer": ["bar"], "source": ["baz"]})
results = evaluate(
model=model,
data=data,
predictions="answer",
# other arguments if needed
)
# Evaluate a static dataset
data = pd.DataFrame({"question": ["foo"], "answer": ["bar"], "source": ["baz"]})
results = evaluate(
data=data,
predictions="answer",
# other arguments if needed
)
dataset_path: (Optional) The path where the data is stored. Must not contain double
quotes (``"``). If specified, the path is logged to the ``mlflow.datasets``
tag for lineage tracking purposes.
feature_names: (Optional) A list. If the ``data`` argument is a numpy array or list,
``feature_names`` is a list of the feature names for each feature. If
``feature_names=None``, then the ``feature_names`` are generated using the
format ``feature_{feature_index}``. If the ``data`` argument is a Pandas
DataFrame or a Spark DataFrame, ``feature_names`` is a list of the names
of the feature columns in the DataFrame. If ``feature_names=None``, then
all columns except the label column and the predictions column are
regarded as feature columns.
evaluators: The name of the evaluator to use for model evaluation, or a list of
evaluator names. If unspecified, all evaluators capable of evaluating the
specified model on the specified dataset are used. The default evaluator
can be referred to by the name ``"default"``. To see all available
evaluators, call :py:func:`mlflow.models.list_evaluators`.
evaluator_config: A dictionary of additional configurations to supply to the evaluator.
If multiple evaluators are specified, each configuration should be
supplied as a nested dictionary whose key is the evaluator name.
extra_metrics:
(Optional) A list of :py:class:`EvaluationMetric <mlflow.models.EvaluationMetric>`
objects. These metrics are computed in addition to the default metrics associated with
pre-defined `model_type`, and setting `model_type=None` will only compute the metrics
specified in `extra_metrics`. See the `mlflow.metrics` module for more information about
the builtin metrics and how to define extra metrics.
.. code-block:: python
:caption: Example usage of extra metrics
import mlflow
import numpy as np
def root_mean_squared_error(eval_df, _builtin_metrics):
return np.sqrt((np.abs(eval_df["prediction"] - eval_df["target"]) ** 2).mean())
rmse_metric = mlflow.models.make_metric(
eval_fn=root_mean_squared_error,
greater_is_better=False,
)
mlflow.evaluate(..., extra_metrics=[rmse_metric])
custom_artifacts:
(Optional) A list of custom artifact functions with the following signature:
.. code-block:: python
def custom_artifact(
eval_df: Union[pandas.Dataframe, pyspark.sql.DataFrame],
builtin_metrics: Dict[str, float],
artifacts_dir: str,
) -> Dict[str, Any]:
"""
Args:
eval_df:
A Pandas or Spark DataFrame containing ``prediction`` and ``target``
column. The ``prediction`` column contains the predictions made by the
model. The ``target`` column contains the corresponding labels to the
predictions made on that row.
builtin_metrics:
A dictionary containing the metrics calculated by the default evaluator.
The keys are the names of the metrics and the values are the scalar
values of the metrics. Refer to the DefaultEvaluator behavior section
for what metrics will be returned based on the type of model (i.e.
classifier or regressor).
artifacts_dir:
A temporary directory path that can be used by the custom artifacts
function to temporarily store produced artifacts. The directory will be
deleted after the artifacts are logged.
Returns:
A dictionary that maps artifact names to artifact objects
(e.g. a Matplotlib Figure) or to artifact paths within ``artifacts_dir``.
"""
...
Object types that artifacts can be represented as:
- A string uri representing the file path to the artifact. MLflow will infer the
type of the artifact based on the file extension.
- A string representation of a JSON object. This will be saved as a .json artifact.
- Pandas DataFrame. This will be resolved as a CSV artifact.
- Numpy array. This will be saved as a .npy artifact.
- Matplotlib Figure. This will be saved as an image artifact. Note that
``matplotlib.pyplot.savefig`` is called behind the scene with default
configurations.
To customize, either save the figure with the desired configurations and return
its file path or define customizations through environment variables in
``matplotlib.rcParams``.
- Other objects will be attempted to be pickled with the default protocol.
.. code-block:: python
:caption: Example usage of custom artifacts
import mlflow
import matplotlib.pyplot as plt
def scatter_plot(eval_df, builtin_metrics, artifacts_dir):
plt.scatter(eval_df["prediction"], eval_df["target"])
plt.xlabel("Targets")
plt.ylabel("Predictions")
plt.title("Targets vs. Predictions")
plt.savefig(os.path.join(artifacts_dir, "example.png"))
plt.close()
return {"pred_target_scatter": os.path.join(artifacts_dir, "example.png")}
def pred_sample(eval_df, _builtin_metrics, _artifacts_dir):
return {"pred_sample": pred_sample.head(10)}
mlflow.evaluate(..., custom_artifacts=[scatter_plot, pred_sample])
env_manager: Specify an environment manager to load the candidate ``model`` in
isolated Python environments and restore their
dependencies. Default value is ``local``, and the following values are
supported:
- ``virtualenv``: (Recommended) Use virtualenv to restore the python
environment that was used to train the model.
- ``conda``: Use Conda to restore the software environment that was used
to train the model.
- ``local``: Use the current Python environment for model inference, which
may differ from the environment used to train the model and may lead to
errors or invalid predictions.
model_config: the model configuration to use for loading the model with pyfunc. Inspect
the model's pyfunc flavor to know which keys are supported for your
specific model. If not indicated, the default model configuration
from the model is used (if any).
inference_params: (Optional) A dictionary of inference parameters to be passed to the model
when making predictions, such as ``{"max_tokens": 100}``. This is only used when
the ``model`` is an MLflow Deployments endpoint URI e.g. ``"endpoints:/my-chat"``
model_id: (Optional) The ID of the MLflow LoggedModel or Model Version to which the
evaluation results (e.g. metrics and traces) will be linked. If `model_id` is not
specified but `model` is specified, the ID from `model` will be used.
_called_from_genai_evaluate: (Optional) Only used internally.
Returns:
An :py:class:`mlflow.models.EvaluationResult` instance containing
metrics of evaluating the model with the given dataset.
mlflow.exceptions
Python Library Documentation: module mlflow.exceptions in mlflow
NAME
mlflow.exceptions
CLASSES
builtins.Exception(builtins.BaseException)
MlflowException
ExecutionException
InvalidUrlException
MissingConfigException
MlflowNotImplementedException
MlflowTracingException
MlflowTraceArchivalMalformedTrace
MlflowTraceDataException
MlflowTraceDataCorrupted
MlflowTraceDataNotFound
RestException
class ExecutionException(MlflowException)
| ExecutionException(message: str, error_code: int = 1, sqlstate: str | None = None, error_class: str | None = None, **kwargs)
|
| Exception thrown when executing a project fails
|
| Method resolution order:
| ExecutionException
| MlflowException
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Methods inherited from MlflowException:
|
| __init__(self, message: str, error_code: int = 1, sqlstate: str | None = None, error_class: str | None = None, **kwargs)
| Args:
| message: The message or exception describing the error that occurred. This will be
| included in the exception's serialized JSON representation.
| error_code: An appropriate error code for the error that occurred; it will be
| included in the exception's serialized JSON representation. This should
| be one of the codes listed in the `mlflow.protos.databricks_pb2` proto.
| sqlstate: A 5-character SQLSTATE code for error classification. If not provided,
| auto-derived from error_code.
| error_class: A descriptive error class name (e.g., "SCHEMA_ENFORCEMENT_FAILED").
| If not provided, auto-derived from error_code.
| kwargs: Additional key-value pairs to include in the serialized JSON representation
| of the MlflowException.
|
| get_http_status_code(self)
|
| serialize_as_json(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from MlflowException:
|
| invalid_parameter_value(message: str, sqlstate: str | None = None, error_class: str | None = None, **kwargs)
| Constructs an `MlflowException` object with the `INVALID_PARAMETER_VALUE` error code.
|
| Args:
| message: The message describing the error that occurred. This will be included in the
| exception's serialized JSON representation.
| sqlstate: A 5-character SQLSTATE code for error classification.
| error_class: A descriptive error class name.
| kwargs: Additional key-value pairs to include in the serialized JSON representation
| of the MlflowException.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from MlflowException:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class InvalidUrlException(MlflowException)
| InvalidUrlException(message: str, error_code: int = 1, sqlstate: str | None = None, error_class: str | None = None, **kwargs)
|
| Exception thrown when a http request fails to send due to an invalid URL
|
| Method resolution order:
| InvalidUrlException
| MlflowException
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Methods inherited from MlflowException:
|
| __init__(self, message: str, error_code: int = 1, sqlstate: str | None = None, error_class: str | None = None, **kwargs)
| Args:
| message: The message or exception describing the error that occurred. This will be
| included in the exception's serialized JSON representation.
| error_code: An appropriate error code for the error that occurred; it will be
| included in the exception's serialized JSON representation. This should
| be one of the codes listed in the `mlflow.protos.databricks_pb2` proto.
| sqlstate: A 5-character SQLSTATE code for error classification. If not provided,
| auto-derived from error_code.
| error_class: A descriptive error class name (e.g., "SCHEMA_ENFORCEMENT_FAILED").
| If not provided, auto-derived from error_code.
| kwargs: Additional key-value pairs to include in the serialized JSON representation
| of the MlflowException.
|
| get_http_status_code(self)
|
| serialize_as_json(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from MlflowException:
|
| invalid_parameter_value(message: str, sqlstate: str | None = None, error_class: str | None = None, **kwargs)
| Constructs an `MlflowException` object with the `INVALID_PARAMETER_VALUE` error code.
|
| Args:
| message: The message describing the error that occurred. This will be included in the
| exception's serialized JSON representation.
| sqlstate: A 5-character SQLSTATE code for error classification.
| error_class: A descriptive error class name.
| kwargs: Additional key-value pairs to include in the serialized JSON representation
| of the MlflowException.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from MlflowException:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class MissingConfigException(MlflowException)
| MissingConfigException(message: str, error_code: int = 1, sqlstate: str | None = None, error_class: str | None = None, **kwargs)
|
| Exception thrown when expected configuration file/directory not found
|
| Method resolution order:
| MissingConfigException
| MlflowException
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Methods inherited from MlflowException:
|
| __init__(self, message: str, error_code: int = 1, sqlstate: str | None = None, error_class: str | None = None, **kwargs)
| Args:
| message: The message or exception describing the error that occurred. This will be
| included in the exception's serialized JSON representation.
| error_code: An appropriate error code for the error that occurred; it will be
| included in the exception's serialized JSON representation. This should
| be one of the codes listed in the `mlflow.protos.databricks_pb2` proto.
| sqlstate: A 5-character SQLSTATE code for error classification. If not provided,
| auto-derived from error_code.
| error_class: A descriptive error class name (e.g., "SCHEMA_ENFORCEMENT_FAILED").
| If not provided, auto-derived from error_code.
| kwargs: Additional key-value pairs to include in the serialized JSON representation
| of the MlflowException.
|
| get_http_status_code(self)
|
| serialize_as_json(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from MlflowException:
|
| invalid_parameter_value(message: str, sqlstate: str | None = None, error_class: str | None = None, **kwargs)
| Constructs an `MlflowException` object with the `INVALID_PARAMETER_VALUE` error code.
|
| Args:
| message: The message describing the error that occurred. This will be included in the
| exception's serialized JSON representation.
| sqlstate: A 5-character SQLSTATE code for error classification.
| error_class: A descriptive error class name.
| kwargs: Additional key-value pairs to include in the serialized JSON representation
| of the MlflowException.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from MlflowException:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class MlflowException(builtins.Exception)
| MlflowException(message: str, error_code: int = 1, sqlstate: str | None = None, error_class: str | None = None, **kwargs)
|
| Generic exception thrown to surface failure information about external-facing operations.
| The error message associated with this exception may be exposed to clients in HTTP responses
| for debugging purposes. If the error text is sensitive, raise a generic `Exception` object
| instead.
|
| Method resolution order:
| MlflowException
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Methods defined here:
|
| __init__(self, message: str, error_code: int = 1, sqlstate: str | None = None, error_class: str | None = None, **kwargs)
| Args:
| message: The message or exception describing the error that occurred. This will be
| included in the exception's serialized JSON representation.
| error_code: An appropriate error code for the error that occurred; it will be
| included in the exception's serialized JSON representation. This should
| be one of the codes listed in the `mlflow.protos.databricks_pb2` proto.
| sqlstate: A 5-character SQLSTATE code for error classification. If not provided,
| auto-derived from error_code.
| error_class: A descriptive error class name (e.g., "SCHEMA_ENFORCEMENT_FAILED").
| If not provided, auto-derived from error_code.
| kwargs: Additional key-value pairs to include in the serialized JSON representation
| of the MlflowException.
|
| get_http_status_code(self)
|
| serialize_as_json(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| invalid_parameter_value(message: str, sqlstate: str | None = None, error_class: str | None = None, **kwargs)
| Constructs an `MlflowException` object with the `INVALID_PARAMETER_VALUE` error code.
|
| Args:
| message: The message describing the error that occurred. This will be included in the
| exception's serialized JSON representation.
| sqlstate: A 5-character SQLSTATE code for error classification.
| error_class: A descriptive error class name.
| kwargs: Additional key-value pairs to include in the serialized JSON representation
| of the MlflowException.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class MlflowNotImplementedException(MlflowException)
| MlflowNotImplementedException(message='')
|
| Exception thrown when a feature is not implemented
|
| Method resolution order:
| MlflowNotImplementedException
| MlflowException
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Methods defined here:
|
| __init__(self, message='')
| Args:
| message: The message or exception describing the error that occurred. This will be
| included in the exception's serialized JSON representation.
| error_code: An appropriate error code for the error that occurred; it will be
| included in the exception's serialized JSON representation. This should
| be one of the codes listed in the `mlflow.protos.databricks_pb2` proto.
| sqlstate: A 5-character SQLSTATE code for error classification. If not provided,
| auto-derived from error_code.
| error_class: A descriptive error class name (e.g., "SCHEMA_ENFORCEMENT_FAILED").
| If not provided, auto-derived from error_code.
| kwargs: Additional key-value pairs to include in the serialized JSON representation
| of the MlflowException.
|
| ----------------------------------------------------------------------
| Methods inherited from MlflowException:
|
| get_http_status_code(self)
|
| serialize_as_json(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from MlflowException:
|
| invalid_parameter_value(message: str, sqlstate: str | None = None, error_class: str | None = None, **kwargs)
| Constructs an `MlflowException` object with the `INVALID_PARAMETER_VALUE` error code.
|
| Args:
| message: The message describing the error that occurred. This will be included in the
| exception's serialized JSON representation.
| sqlstate: A 5-character SQLSTATE code for error classification.
| error_class: A descriptive error class name.
| kwargs: Additional key-value pairs to include in the serialized JSON representation
| of the MlflowException.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from MlflowException:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class MlflowTraceArchivalMalformedTrace(MlflowTracingException)
| MlflowTraceArchivalMalformedTrace(message)
|
| Exception thrown when archived trace serialization detects malformed trace content.
|
| Method resolution order:
| MlflowTraceArchivalMalformedTrace
| MlflowTracingException
| MlflowException
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Methods defined here:
|
| __init__(self, message)
| Args:
| message: The message or exception describing the error that occurred. This will be
| included in the exception's serialized JSON representation.
| error_code: An appropriate error code for the error that occurred; it will be
| included in the exception's serialized JSON representation. This should
| be one of the codes listed in the `mlflow.protos.databricks_pb2` proto.
| sqlstate: A 5-character SQLSTATE code for error classification. If not provided,
| auto-derived from error_code.
| error_class: A descriptive error class name (e.g., "SCHEMA_ENFORCEMENT_FAILED").
| If not provided, auto-derived from error_code.
| kwargs: Additional key-value pairs to include in the serialized JSON representation
| of the MlflowException.
|
| ----------------------------------------------------------------------
| Methods inherited from MlflowException:
|
| get_http_status_code(self)
|
| serialize_as_json(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from MlflowException:
|
| invalid_parameter_value(message: str, sqlstate: str | None = None, error_class: str | None = None, **kwargs)
| Constructs an `MlflowException` object with the `INVALID_PARAMETER_VALUE` error code.
|
| Args:
| message: The message describing the error that occurred. This will be included in the
| exception's serialized JSON representation.
| sqlstate: A 5-character SQLSTATE code for error classification.
| error_class: A descriptive error class name.
| kwargs: Additional key-value pairs to include in the serialized JSON representation
| of the MlflowException.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from MlflowException:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class MlflowTraceDataCorrupted(MlflowTraceDataException)
| MlflowTraceDataCorrupted(request_id: str | None = None, artifact_path: str | None = None)
|
| Exception thrown when trace data is corrupted
|
| Method resolution order:
| MlflowTraceDataCorrupted
| MlflowTraceDataException
| MlflowTracingException
| MlflowException
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Methods defined here:
|
| __init__(self, request_id: str | None = None, artifact_path: str | None = None)
| Args:
| message: The message or exception describing the error that occurred. This will be
| included in the exception's serialized JSON representation.
| error_code: An appropriate error code for the error that occurred; it will be
| included in the exception's serialized JSON representation. This should
| be one of the codes listed in the `mlflow.protos.databricks_pb2` proto.
| sqlstate: A 5-character SQLSTATE code for error classification. If not provided,
| auto-derived from error_code.
| error_class: A descriptive error class name (e.g., "SCHEMA_ENFORCEMENT_FAILED").
| If not provided, auto-derived from error_code.
| kwargs: Additional key-value pairs to include in the serialized JSON representation
| of the MlflowException.
|
| ----------------------------------------------------------------------
| Methods inherited from MlflowException:
|
| get_http_status_code(self)
|
| serialize_as_json(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from MlflowException:
|
| invalid_parameter_value(message: str, sqlstate: str | None = None, error_class: str | None = None, **kwargs)
| Constructs an `MlflowException` object with the `INVALID_PARAMETER_VALUE` error code.
|
| Args:
| message: The message describing the error that occurred. This will be included in the
| exception's serialized JSON representation.
| sqlstate: A 5-character SQLSTATE code for error classification.
| error_class: A descriptive error class name.
| kwargs: Additional key-value pairs to include in the serialized JSON representation
| of the MlflowException.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from MlflowException:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class MlflowTraceDataException(MlflowTracingException)
| MlflowTraceDataException(error_code: str, request_id: str | None = None, artifact_path: str | None = None)
|
| Exception thrown for trace data related error
|
| Method resolution order:
| MlflowTraceDataException
| MlflowTracingException
| MlflowException
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Methods defined here:
|
| __init__(self, error_code: str, request_id: str | None = None, artifact_path: str | None = None)
| Args:
| message: The message or exception describing the error that occurred. This will be
| included in the exception's serialized JSON representation.
| error_code: An appropriate error code for the error that occurred; it will be
| included in the exception's serialized JSON representation. This should
| be one of the codes listed in the `mlflow.protos.databricks_pb2` proto.
| sqlstate: A 5-character SQLSTATE code for error classification. If not provided,
| auto-derived from error_code.
| error_class: A descriptive error class name (e.g., "SCHEMA_ENFORCEMENT_FAILED").
| If not provided, auto-derived from error_code.
| kwargs: Additional key-value pairs to include in the serialized JSON representation
| of the MlflowException.
|
| ----------------------------------------------------------------------
| Methods inherited from MlflowException:
|
| get_http_status_code(self)
|
| serialize_as_json(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from MlflowException:
|
| invalid_parameter_value(message: str, sqlstate: str | None = None, error_class: str | None = None, **kwargs)
| Constructs an `MlflowException` object with the `INVALID_PARAMETER_VALUE` error code.
|
| Args:
| message: The message describing the error that occurred. This will be included in the
| exception's serialized JSON representation.
| sqlstate: A 5-character SQLSTATE code for error classification.
| error_class: A descriptive error class name.
| kwargs: Additional key-value pairs to include in the serialized JSON representation
| of the MlflowException.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from MlflowException:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class MlflowTraceDataNotFound(MlflowTraceDataException)
| MlflowTraceDataNotFound(request_id: str | None = None, artifact_path: str | None = None)
|
| Exception thrown when trace data is not found
|
| Method resolution order:
| MlflowTraceDataNotFound
| MlflowTraceDataException
| MlflowTracingException
| MlflowException
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Methods defined here:
|
| __init__(self, request_id: str | None = None, artifact_path: str | None = None)
| Args:
| message: The message or exception describing the error that occurred. This will be
| included in the exception's serialized JSON representation.
| error_code: An appropriate error code for the error that occurred; it will be
| included in the exception's serialized JSON representation. This should
| be one of the codes listed in the `mlflow.protos.databricks_pb2` proto.
| sqlstate: A 5-character SQLSTATE code for error classification. If not provided,
| auto-derived from error_code.
| error_class: A descriptive error class name (e.g., "SCHEMA_ENFORCEMENT_FAILED").
| If not provided, auto-derived from error_code.
| kwargs: Additional key-value pairs to include in the serialized JSON representation
| of the MlflowException.
|
| ----------------------------------------------------------------------
| Methods inherited from MlflowException:
|
| get_http_status_code(self)
|
| serialize_as_json(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from MlflowException:
|
| invalid_parameter_value(message: str, sqlstate: str | None = None, error_class: str | None = None, **kwargs)
| Constructs an `MlflowException` object with the `INVALID_PARAMETER_VALUE` error code.
|
| Args:
| message: The message describing the error that occurred. This will be included in the
| exception's serialized JSON representation.
| sqlstate: A 5-character SQLSTATE code for error classification.
| error_class: A descriptive error class name.
| kwargs: Additional key-value pairs to include in the serialized JSON representation
| of the MlflowException.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from MlflowException:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class MlflowTracingException(MlflowException)
| MlflowTracingException(message, error_code=1)
|
| Exception thrown from tracing logic
|
| Tracing logic should not block the main execution flow in general, hence this exception
| is used to distinguish tracing related errors and handle them properly.
|
| Method resolution order:
| MlflowTracingException
| MlflowException
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Methods defined here:
|
| __init__(self, message, error_code=1)
| Args:
| message: The message or exception describing the error that occurred. This will be
| included in the exception's serialized JSON representation.
| error_code: An appropriate error code for the error that occurred; it will be
| included in the exception's serialized JSON representation. This should
| be one of the codes listed in the `mlflow.protos.databricks_pb2` proto.
| sqlstate: A 5-character SQLSTATE code for error classification. If not provided,
| auto-derived from error_code.
| error_class: A descriptive error class name (e.g., "SCHEMA_ENFORCEMENT_FAILED").
| If not provided, auto-derived from error_code.
| kwargs: Additional key-value pairs to include in the serialized JSON representation
| of the MlflowException.
|
| ----------------------------------------------------------------------
| Methods inherited from MlflowException:
|
| get_http_status_code(self)
|
| serialize_as_json(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from MlflowException:
|
| invalid_parameter_value(message: str, sqlstate: str | None = None, error_class: str | None = None, **kwargs)
| Constructs an `MlflowException` object with the `INVALID_PARAMETER_VALUE` error code.
|
| Args:
| message: The message describing the error that occurred. This will be included in the
| exception's serialized JSON representation.
| sqlstate: A 5-character SQLSTATE code for error classification.
| error_class: A descriptive error class name.
| kwargs: Additional key-value pairs to include in the serialized JSON representation
| of the MlflowException.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from MlflowException:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class RestException(MlflowException)
| RestException(json)
|
| Exception thrown on non 200-level responses from the REST API
|
| Method resolution order:
| RestException
| MlflowException
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Methods defined here:
|
| __init__(self, json)
| Args:
| message: The message or exception describing the error that occurred. This will be
| included in the exception's serialized JSON representation.
| error_code: An appropriate error code for the error that occurred; it will be
| included in the exception's serialized JSON representation. This should
| be one of the codes listed in the `mlflow.protos.databricks_pb2` proto.
| sqlstate: A 5-character SQLSTATE code for error classification. If not provided,
| auto-derived from error_code.
| error_class: A descriptive error class name (e.g., "SCHEMA_ENFORCEMENT_FAILED").
| If not provided, auto-derived from error_code.
| kwargs: Additional key-value pairs to include in the serialized JSON representation
| of the MlflowException.
|
| __reduce__(self)
| Overriding `__reduce__` to make `RestException` instance pickle-able.
|
| ----------------------------------------------------------------------
| Methods inherited from MlflowException:
|
| get_http_status_code(self)
|
| serialize_as_json(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from MlflowException:
|
| invalid_parameter_value(message: str, sqlstate: str | None = None, error_class: str | None = None, **kwargs)
| Constructs an `MlflowException` object with the `INVALID_PARAMETER_VALUE` error code.
|
| Args:
| message: The message describing the error that occurred. This will be included in the
| exception's serialized JSON representation.
| sqlstate: A 5-character SQLSTATE code for error classification.
| error_class: A descriptive error class name.
| kwargs: Additional key-value pairs to include in the serialized JSON representation
| of the MlflowException.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from MlflowException:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
FUNCTIONS
get_error_code(http_status)
DATA
ABORTED = 10
ALREADY_EXISTS = 12
BAD_REQUEST = 4
CANCELLED = 8
CUSTOMER_UNAUTHORIZED = 1006
DATA_LOSS = 1011
DEADLINE_EXCEEDED = 7
ENDPOINT_NOT_FOUND = 1001
ERROR_CODE_TO_HTTP_STATUS = {'ABORTED': 409, 'ALREADY_EXISTS': 409, 'B...
ErrorCode = <google.protobuf.internal.enum_type_wrapper.EnumTypeWrappe...
HTTP_STATUS_TO_ERROR_CODE = {400: 'BAD_REQUEST', 401: 'UNAUTHENTICATED...
INTERNAL_ERROR = 1
INVALID_PARAMETER_VALUE = 1000
INVALID_STATE = 1003
NOT_FOUND = 11
NOT_IMPLEMENTED = 1010
PERMISSION_DENIED = 1004
REQUEST_LIMIT_EXCEEDED = 1007
RESOURCE_ALREADY_EXISTS = 3001
RESOURCE_CONFLICT = 1008
RESOURCE_DOES_NOT_EXIST = 3002
RESOURCE_EXHAUSTED = 9
TEMPORARILY_UNAVAILABLE = 2
UNAUTHENTICATED = 13
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\exceptions.py
mlflow.finalize_logged_model
Python Library Documentation: function finalize_logged_model in module mlflow.tracking.fluent
finalize_logged_model(model_id: str, status: Union[Literal['READY', 'FAILED'], mlflow.entities.logged_model_status.LoggedModelStatus]) -> mlflow.entities.logged_model.LoggedModel
Finalize a model by updating its status.
Args:
model_id: ID of the model to finalize.
status: Final status to set on the model.
Returns:
The updated model.
Example:
.. code-block:: python
:test:
import mlflow
from mlflow.entities import LoggedModelStatus
model = mlflow.initialize_logged_model(name="model")
logged_model = mlflow.finalize_logged_model(
model_id=model.model_id,
status=LoggedModelStatus.READY,
)
assert logged_model.status == LoggedModelStatus.READY
mlflow.flush_artifact_async_logging
Python Library Documentation: function flush_artifact_async_logging in module mlflow.tracking.fluent
flush_artifact_async_logging() -> None
Flush all pending artifact async logging.
mlflow.flush_async_logging
Python Library Documentation: function flush_async_logging in module mlflow.tracking.fluent
flush_async_logging() -> None
Flush all pending async logging.
mlflow.flush_trace_async_logging
Python Library Documentation: function flush_trace_async_logging in module mlflow.tracking.fluent
flush_trace_async_logging(terminate=False) -> None
Flush all pending trace async logging.
Args:
terminate: If True, shut down the logging threads after flushing.
mlflow.gateway
Python Library Documentation: package mlflow.gateway in mlflow
NAME
mlflow.gateway
PACKAGE CONTENTS
app
base_models
budget
budget_tracker (package)
cli
config
constants
exceptions
guardrail_utils
guardrails
provider_registry
providers (package)
runner
schemas (package)
tracing_utils
uc_function_utils
utils
FUNCTIONS
get_gateway_uri() -> str
Returns the currently set MLflow AI Gateway server uri iff set.
If the Gateway uri has not been set by using ``set_gateway_uri``, an ``MlflowException``
is raised.
set_gateway_uri(gateway_uri: str)
Sets the uri of a configured and running MLflow AI Gateway server in a global context.
Providing a valid uri and calling this function is required in order to use the MLflow
AI Gateway fluent APIs.
Args:
gateway_uri: The full uri of a running MLflow AI Gateway server or, if running on
Databricks, "databricks".
DATA
__all__ = ['get_gateway_uri', 'set_gateway_uri']
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\gateway\__init__.py
mlflow.gemini
Python Library Documentation: package mlflow.gemini in mlflow
NAME
mlflow.gemini - The ``mlflow.gemini`` module provides an API for tracing the interaction with Gemini models.
PACKAGE CONTENTS
autolog
chat
genai_semconv_converter
DATA
FLAVOR_NAME = 'gemini'
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\gemini\__init__.py
mlflow.genai
Python Library Documentation: package mlflow.genai in mlflow
NAME
mlflow.genai
PACKAGE CONTENTS
agent_server (package)
agent_tester
datasets (package)
discovery (package)
evaluation (package)
git_versioning (package)
judges (package)
label_schemas (package)
labeling (package)
mcp_servers
mcp_tool_discovery
optimize (package)
prompts (package)
review_queues (package)
scheduled_scorers
scorers (package)
simulators (package)
utils (package)
CLASSES
builtins.object
mlflow.genai.labeling.labeling.Agent
mlflow.genai.labeling.labeling.LabelingSession
mlflow.genai.labeling.labeling.ReviewApp
mlflow.genai.scheduled_scorers.ScorerScheduleConfig
mlflow.genai.simulators.simulator.ConversationSimulator
pydantic.main.BaseModel(builtins.object)
mlflow.genai.scorers.base.Scorer
class Agent(builtins.object)
| Agent(agent: '_Agent')
|
| The agent configuration, used for generating responses in the review app.
|
| .. note::
| This functionality is only available in Databricks. Please run
| `pip install mlflow[databricks]` to use it.
|
| Methods defined here:
|
| __init__(self, agent: '_Agent')
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| agent_name
| The name of the agent.
|
| model_serving_endpoint
| The model serving endpoint used by the agent.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class ConversationSimulator(builtins.object)
| ConversationSimulator(test_cases: "list[dict[str, Any]] | 'DataFrame' | EvaluationDataset", max_turns: 'int' = 10, user_model: 'str | None' = None, user_agent_class: 'type[BaseSimulatedUserAgent] | None' = None, **user_llm_params)
|
| .. Note:: Experimental: This class may change or be removed in a future release without warning.
|
|
| Generates multi-turn conversations by simulating user interactions with a target agent.
|
| The simulator creates a simulated user agent that interacts with your agent's predict function.
| Each conversation is traced in MLflow, allowing you to evaluate how your agent handles
| various user goals and personas.
|
| The predict function passed to the simulator must accept the conversation history
| as a list of message dictionaries (e.g., ``[{"role": "user", "content": "..."}]``).
| Two formats are supported:
|
| - **Responses API format**: Use an ``input`` parameter
| (https://platform.openai.com/docs/api-reference/responses)
| - **Chat Completions API format**: Use a ``messages`` parameter
| (https://platform.openai.com/docs/api-reference/chat)
|
| The predict function:
|
| - Must accept either ``input`` or ``messages`` (not both) for the conversation history
| - May accept additional keyword arguments from the test case's ``context`` field
| - Receives an ``mlflow_session_id`` parameter that uniquely identifies the conversation
| session. This ID is consistent across all turns in the same conversation, allowing you
| to associate related traces or maintain stateful context (e.g., for thread-based agents).
| - Should return a response (the assistant's message content will be extracted)
|
| Args:
| test_cases: List of test case dicts, a DataFrame, or an EvaluationDataset,
| with the following fields:
|
| - "goal": Describing what the simulated user wants to achieve.
| - "persona" (optional): Custom persona for the simulated user.
| - "context" (optional): Dict of additional kwargs to pass to predict_fn.
| Keys ``input``, ``messages``, and ``mlflow_session_id`` are reserved
| by the simulator and cannot be used.
| - "expectations" (optional): Dict of expected values (ground truth) for
| session-level evaluation. These are logged to the first trace of the
| session with the session ID in metadata, allowing session-level scorers
| to retrieve them.
| - "simulation_guidelines" (optional): Instructions for how the simulated user
| should conduct the conversation. Can be a string or a list of strings.
|
| max_turns: Maximum number of conversation turns before stopping. Default is 10.
| user_model: Model to use for generating user messages. Must be one of:
|
| * `"databricks"` - Uses the Databricks managed LLM endpoint
| * `"databricks:/<endpoint-name>"` - Uses a Databricks model serving endpoint (e.g., `"databricks:/databricks-claude-sonnet-4-5"`)
| * `"gateway:/<endpoint-name>"` - Uses an MLflow AI Gateway endpoint (e.g., `"gateway:/my-chat-endpoint"`)
| * `"<provider>:/<model-name>"` - Uses LiteLLM (e.g., `"openai:/gpt-4.1-mini"`, `"anthropic:/claude-3.5-sonnet-20240620"`)
|
| MLflow natively supports `["openai", "anthropic", "bedrock", "mistral"]`, and more providers are supported through `LiteLLM <https://docs.litellm.ai/docs/providers>`_.
|
| Default model depends on the tracking URI setup:
|
| * Databricks: `"databricks"`
| * Otherwise: `"openai:/gpt-4.1-mini"`
| user_agent_class: Optional custom simulated user agent class. Must be a subclass
| of :py:class:`BaseSimulatedUserAgent`. If not provided, uses the default
| :py:class:`SimulatedUserAgent`.
| **user_llm_params: Additional parameters passed to the simulated user's LLM calls.
|
| Example:
| .. code-block:: python
|
| import mlflow
| from mlflow.genai.simulators import ConversationSimulator
| from mlflow.genai.scorers import ConversationalSafety, Safety
|
| # Dummy cache to store conversation threads by session ID
| conversation_threads = {}
|
|
| def predict_fn(input: list[dict], **kwargs) -> dict:
| # The mlflow_session_id uniquely identifies this conversation session.
| # All turns in the same conversation share the same session ID.
| session_id = kwargs.get("mlflow_session_id")
|
| # Use the session ID to maintain state across turns - for example,
| # storing conversation context, user preferences, or agent memory
| if session_id not in conversation_threads:
| conversation_threads[session_id] = {"turn_count": 0}
| conversation_threads[session_id]["turn_count"] += 1
|
| response = client.chat.completions.create(
| model="gpt-4o-mini",
| messages=input,
| )
| return response
|
|
| # Each test case requires a "goal". "persona", "context", "expectations",
| # and "simulation_guidelines" are optional.
| simulator = ConversationSimulator(
| test_cases=[
| {"goal": "Learn about MLflow tracking"},
| {"goal": "Debug deployment issue", "persona": "A data scientist"},
| {
| "goal": "Set up model registry",
| "persona": "A beginner",
| "context": {"user_id": "123"},
| "expectations": {"expected_topic": "model registry"},
| "simulation_guidelines": [
| "Ask clarifying questions before proceeding",
| "Do not mention deployment until the assistant brings it up",
| ],
| },
| ],
| max_turns=5,
| )
|
| mlflow.genai.evaluate(
| data=simulator,
| predict_fn=predict_fn,
| scorers=[ConversationalSafety(), Safety()],
| )
|
| Methods defined here:
|
| __init__(self, test_cases: "list[dict[str, Any]] | 'DataFrame' | EvaluationDataset", max_turns: 'int' = 10, user_model: 'str | None' = None, user_agent_class: 'type[BaseSimulatedUserAgent] | None' = None, **user_llm_params)
| Initialize self. See help(type(self)) for accurate signature.
|
| __setattr__(self, name: 'str', value: 'Any') -> 'None'
| Implement setattr(self, name, value).
|
| simulate(self, predict_fn: 'Callable[..., dict[str, Any]]') -> "list[list['Trace']]"
| .. Note:: Experimental: This function may change or be removed in a future release without warning.
|
|
| Run conversation simulations for all test cases.
|
| Executes the simulated user agent against the provided predict function
| for each test case, generating multi-turn conversations. Each conversation
| is traced in MLflow.
|
| Args:
| predict_fn: The target function to evaluate. Must accept either an ``input``
| parameter (Responses API format) or a ``messages`` parameter (Chat
| Completions API format) containing the conversation history as a list of
| message dicts. May also accept additional kwargs from the test case's
| context. Cannot have both ``input`` and ``messages`` parameters.
|
| Returns:
| A list of lists containing Trace objects. Each inner list corresponds to
| a test case and contains the traces for each turn in that conversation.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class LabelingSession(builtins.object)
| LabelingSession(*, name: str, assigned_users: list[str], agent: str | None, label_schemas: list[str], labeling_session_id: str, mlflow_run_id: str, review_app_id: str, experiment_id: str, url: str, enable_multi_turn_chat: bool, custom_inputs: dict[str, typing.Any] | None)
|
| A session for labeling items in the review app.
|
| .. note::
| This functionality is only available in Databricks. Please run
| `pip install mlflow[databricks]` to use it.
|
| Methods defined here:
|
| __init__(self, *, name: str, assigned_users: list[str], agent: str | None, label_schemas: list[str], labeling_session_id: str, mlflow_run_id: str, review_app_id: str, experiment_id: str, url: str, enable_multi_turn_chat: bool, custom_inputs: dict[str, typing.Any] | None)
| Initialize self. See help(type(self)) for accurate signature.
|
| add_dataset(self, dataset_name: str, record_ids: list[str] | None = None) -> 'LabelingSession'
| Add a dataset to the labeling session.
|
| .. note::
| This functionality is only available in Databricks. Please run
| `pip install mlflow[databricks]` to use it.
|
| Args:
| dataset_name: The name of the dataset.
| record_ids: Optional. The individual record ids to be added to the session. If not
| provided, all records in the dataset will be added.
|
| Returns:
| LabelingSession: The updated labeling session.
|
| add_traces(self, traces: Union[Iterable[mlflow.entities.trace.Trace], Iterable[str], ForwardRef('pd.DataFrame')]) -> 'LabelingSession'
| Add traces to the labeling session.
|
| .. note::
| This functionality is only available in Databricks. Please run
| `pip install mlflow[databricks]` to use it.
|
| Args:
| traces: Can be either:
| a) a pandas DataFrame with a 'trace' column. The 'trace' column should contain
| either `mlflow.entities.Trace` objects or their json string representations.
| b) an iterable of `mlflow.entities.Trace` objects.
| c) an iterable of json string representations of `mlflow.entities.Trace` objects.
|
| Returns:
| LabelingSession: The updated labeling session.
|
| set_assigned_users(self, assigned_users: list[str]) -> 'LabelingSession'
| Set the assigned users for the labeling session.
|
| .. note::
| This functionality is only available in Databricks. Please run
| `pip install mlflow[databricks]` to use it.
|
| Args:
| assigned_users: The list of users to assign to the session.
|
| Returns:
| LabelingSession: The updated labeling session.
|
| sync(self, to_dataset: str) -> None
| Sync the traces and expectations from the labeling session to a dataset.
|
| .. note::
| This functionality is only available in Databricks. Please run
| `pip install mlflow[databricks]` to use it.
|
| Args:
| to_dataset: The name of the dataset to sync traces and expectations to.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| agent
| The agent used to generate responses for the items in the session.
|
| assigned_users
| The users assigned to label items in the session.
|
| custom_inputs
| Custom inputs used in the session.
|
| enable_multi_turn_chat
| Whether multi-turn chat is enabled for the session.
|
| experiment_id
| The experiment ID associated with the session.
|
| label_schemas
| The label schemas used in the session.
|
| labeling_session_id
| The unique identifier of the labeling session.
|
| mlflow_run_id
| The MLflow run ID associated with the session.
|
| name
| The name of the labeling session.
|
| review_app_id
| The review app ID associated with the session.
|
| url
| The URL of the labeling session in the review app.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class ReviewApp(builtins.object)
| ReviewApp(app: '_ReviewApp')
|
| A review app is used to collect feedback from stakeholders for a given experiment.
|
| .. note::
| This functionality is only available in Databricks. Please run
| `pip install mlflow[databricks]` to use it.
|
| Methods defined here:
|
| __init__(self, app: '_ReviewApp')
| Initialize self. See help(type(self)) for accurate signature.
|
| add_agent(self, *, agent_name: str, model_serving_endpoint: str, overwrite: bool = False) -> 'ReviewApp'
| Add an agent to the review app to be used to generate responses.
|
| .. note::
| This functionality is only available in Databricks. Please run
| `pip install mlflow[databricks]` to use it.
|
| Args:
| agent_name: The name of the agent.
| model_serving_endpoint: The model serving endpoint to be used by the agent.
| overwrite: Whether to overwrite an existing agent with the same name.
|
| Returns:
| ReviewApp: The updated review app.
|
| remove_agent(self, agent_name: str) -> 'ReviewApp'
| Remove an agent from the review app.
|
| .. note::
| This functionality is only available in Databricks. Please run
| `pip install mlflow[databricks]` to use it.
|
| Args:
| agent_name: The name of the agent to remove.
|
| Returns:
| ReviewApp: The updated review app.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| agents
| The agents to be used to generate responses.
|
| experiment_id
| The ID of the experiment.
|
| label_schemas
| The label schemas to be used in the review app.
|
| review_app_id
| The ID of the review app.
|
| url
| The URL of the review app for stakeholders to provide feedback.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class Scorer(pydantic.main.BaseModel)
| Scorer(*, name: str, aggregations: list[typing.Union[typing.Literal['min', 'max', 'mean', 'median', 'variance', 'p90'], typing.Callable[[list[int | float]], float]]] | None = None, description: str | None = None) -> None
|
| Method resolution order:
| Scorer
| pydantic.main.BaseModel
| builtins.object
|
| Methods defined here:
|
| __call__(self, *, inputs: Any = None, outputs: Any = None, expectations: dict[str, typing.Any] | None = None, trace: mlflow.entities.trace.Trace | None = None, session: list[mlflow.entities.trace.Trace] | None = None) -> int | float | bool | str | mlflow.entities.assessment.Feedback | list[mlflow.entities.assessment.Feedback]
| Implement the custom scorer's logic here.
|
|
| The scorer will be called for each row in the input evaluation dataset.
|
| Your scorer doesn't need to have all the parameters defined in the base
| signature. You can define a custom scorer with only the parameters you need.
| See the parameter details below for what values are passed for each parameter.
|
| .. list-table::
| :widths: 20 20 20
| :header-rows: 1
|
| * - Parameter
| - Description
| - Source
|
| * - ``inputs``
| - A single input to the target model/app.
| - Derived from either dataset or trace.
|
| * When the dataset contains ``inputs`` column, the value will be
| passed as is.
| * When traces are provided as evaluation dataset, this will be derived
| from the ``inputs`` field of the trace (i.e. inputs captured as the
| root span of the trace).
|
| * - ``outputs``
| - A single output from the target model/app.
| - Derived from either dataset, trace, or output of ``predict_fn``.
|
| * When the dataset contains ``outputs`` column, the value will be
| passed as is.
| * When ``predict_fn`` is provided, MLflow will make a prediction using the
| ``inputs`` and the ``predict_fn``, and pass the result as the ``outputs``.
| * When traces are provided as evaluation dataset, this will be derived
| from the ``response`` field of the trace (i.e. outputs captured as the
| root span of the trace).
|
| * - ``expectations``
| - Ground truth or any expectation for each prediction, e.g. expected retrieved docs.
| - Derived from either dataset or trace.
|
| * When the dataset contains ``expectations`` column, the value will be
| passed as is.
| * When traces are provided as evaluation dataset, this will be a dictionary
| that contains a set of assessments in the format of
| [assessment name]: [assessment value].
|
| * - ``trace``
| - A trace object corresponding to the prediction for the row.
| - Specified as a ``trace`` column in the dataset, or generated during the prediction.
|
| * - ``session``
| - A list of trace objects belonging to the same conversation session.
| - Specify this parameter only for session_level scorers
| (scorers with ``is_session_level_scorer = True``).
| * Only traces with the same ``mlflow.trace.session`` metadata value can be passed in
| this parameter, otherwise an error will be raised.
|
| Example:
|
| .. code-block:: python
|
| class NotEmpty(BaseScorer):
| name = "not_empty"
|
| def __call__(self, *, outputs) -> bool:
| return outputs != ""
|
|
| class ExactMatch(BaseScorer):
| name = "exact_match"
|
| def __call__(self, *, outputs, expectations) -> bool:
| return outputs == expectations["expected_response"]
|
|
| class NumToolCalls(BaseScorer):
| name = "num_tool_calls"
|
| def __call__(self, *, trace) -> int:
| spans = trace.search_spans(name="tool_call")
| return len(spans)
|
|
| # Use the scorer in an evaluation
| mlflow.genai.evaluate(
| data=data,
| scorers=[NotEmpty(), ExactMatch(), NumToolCalls()],
| )
|
| __repr__(self) -> str
| Return repr(self).
|
| model_dump(self, **kwargs) -> dict[str, typing.Any]
| Override model_dump to include source code.
|
| model_post_init = init_private_attributes(self: 'BaseModel', context: 'Any', /) -> 'None' from pydantic._internal._model_construction
| This function is meant to behave like a BaseModel method to initialize private attributes.
|
| It takes context as an argument since that's what pydantic-core passes when calling it.
|
| Args:
| self: The BaseModel instance.
| context: The context.
|
| register(self, *, name: str | None = None, experiment_id: str | None = None) -> 'Scorer'
| Register this scorer with the MLflow server.
|
| This method registers the scorer for use with automatic trace evaluation in the
| specified experiment. Once registered, the scorer can be started to begin
| evaluating traces automatically.
|
| Args:
| name: Optional registered name for the scorer. If not provided, the current `name`
| property value will be used as a registered name.
| experiment_id: The ID of the MLflow experiment to register the scorer for.
| If None, uses the currently active experiment.
|
| Returns:
| A new Scorer instance with server registration information.
|
| Example:
|
| .. code-block:: python
|
| import mlflow
| from mlflow.genai.scorers import RelevanceToQuery
|
| # Register a built-in scorer
| mlflow.set_experiment("my_genai_app")
| registered_scorer = RelevanceToQuery().register(name="relevance_scorer")
| print(f"Registered scorer: {registered_scorer.name}")
|
| # Register a custom scorer
| from mlflow.genai.scorers import scorer
|
|
| @scorer
| def custom_length_check(outputs) -> bool:
| return len(outputs) > 100
|
|
| registered_custom = custom_length_check.register(
| name="output_length_checker", experiment_id="12345"
| )
|
| run(self, *, inputs=None, outputs=None, expectations=None, trace=None, session=None)
|
| start(self, *, name: str | None = None, experiment_id: str | None = None, sampling_config: mlflow.genai.scorers.base.ScorerSamplingConfig) -> 'Scorer'
| .. Note:: Experimental: This function may change or be removed in a future release without warning.
|
|
| Start registered scoring with the specified sampling configuration.
|
| This method activates automatic trace evaluation for the scorer. The scorer will
| evaluate traces based on the provided sampling configuration, including the
| sample rate and optional filter criteria.
|
| Args:
| name: Optional scorer name. If not provided, uses the scorer's registered
| name or default name.
| experiment_id: The ID of the MLflow experiment containing the scorer.
| If None, uses the currently active experiment.
| sampling_config: Configuration object containing:
| - sample_rate: Fraction of traces to evaluate (0.0 to 1.0). Required.
| - filter_string: Optional MLflow search_traces compatible filter string.
|
| Returns:
| A new Scorer instance with updated sampling configuration.
|
| Example:
| .. code-block:: python
|
| import mlflow
| from mlflow.genai.scorers import RelevanceToQuery, ScorerSamplingConfig
|
| # Start scorer with 50% sampling rate
| mlflow.set_experiment("my_genai_app")
| scorer = RelevanceToQuery().register()
| active_scorer = scorer.start(sampling_config=ScorerSamplingConfig(sample_rate=0.5))
| print(f"Scorer is evaluating {active_scorer.sample_rate * 100}% of traces")
|
| # Start scorer with filter to only evaluate specific traces
| filtered_scorer = scorer.start(
| sampling_config=ScorerSamplingConfig(
| sample_rate=1.0, filter_string="YOUR_FILTER_STRING"
| )
| )
|
| stop(self, *, name: str | None = None, experiment_id: str | None = None) -> 'Scorer'
| .. Note:: Experimental: This function may change or be removed in a future release without warning.
|
|
| Stop registered scoring by setting sample rate to 0.
|
| This method deactivates automatic trace evaluation for the scorer while keeping
| the scorer registered. The scorer can be restarted later using the start() method.
|
| Args:
| name: Optional scorer name. If not provided, uses the scorer's registered name
| or default name.
| experiment_id: The ID of the MLflow experiment containing the scorer.
| If None, uses the currently active experiment.
|
| Returns:
| A new Scorer instance with sample rate set to 0.
|
| Example:
|
| .. code-block:: python
|
| import mlflow
| from mlflow.genai.scorers import RelevanceToQuery, ScorerSamplingConfig
|
| # Start and then stop a scorer
| mlflow.set_experiment("my_genai_app")
| scorer = RelevanceToQuery().register()
| active_scorer = scorer.start(sampling_config=ScorerSamplingConfig(sample_rate=0.5))
| print(f"Scorer is active: {active_scorer.sample_rate > 0}")
|
| # Stop the scorer
| stopped_scorer = active_scorer.stop()
| print(f"Scorer is active: {stopped_scorer.sample_rate > 0}")
|
| # The scorer remains registered and can be restarted later
| restarted_scorer = stopped_scorer.start(
| sampling_config=ScorerSamplingConfig(sample_rate=0.3)
| )
|
| update(self, *, name: str | None = None, experiment_id: str | None = None, sampling_config: mlflow.genai.scorers.base.ScorerSamplingConfig) -> 'Scorer'
| .. Note:: Experimental: This function may change or be removed in a future release without warning.
|
|
| Update the sampling configuration for this scorer.
|
| This method modifies the sampling rate and/or filter criteria for an already
| registered scorer. It can be used to dynamically adjust how many traces are
| evaluated or change the filtering criteria without stopping and restarting
| the scorer.
|
| Args:
| name: Optional scorer name. If not provided, uses the scorer's registered name
| or default name.
| experiment_id: The ID of the MLflow experiment containing the scorer.
| If None, uses the currently active experiment.
| sampling_config: Configuration object containing:
| - sample_rate: New fraction of traces to evaluate (0.0 to 1.0). Optional.
| - filter_string: New MLflow search_traces compatible filter string. Optional.
|
| Returns:
| A new Scorer instance with updated configuration.
|
| Example:
|
| .. code-block:: python
|
| import mlflow
| from mlflow.genai.scorers import RelevanceToQuery, ScorerSamplingConfig
|
| # Start scorer with initial configuration
| mlflow.set_experiment("my_genai_app")
| scorer = RelevanceToQuery().register()
| active_scorer = scorer.start(sampling_config=ScorerSamplingConfig(sample_rate=0.1))
|
| # Update to increase sampling rate during high traffic
| updated_scorer = active_scorer.update(
| sampling_config=ScorerSamplingConfig(sample_rate=0.5)
| )
| print(f"Updated sample rate: {updated_scorer.sample_rate}")
|
| # Update to add filtering criteria
| filtered_scorer = updated_scorer.update(
| sampling_config=ScorerSamplingConfig(filter_string="YOUR_FILTER_STRING")
| )
| print(f"Added filter: {filtered_scorer.filter_string}")
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __init_subclass__(**kwargs)
| This method is called when a class is subclassed.
|
| The default implementation does nothing. It may be
| overridden to extend subclasses.
|
| model_validate(obj: Any) -> 'Scorer'
| Override model_validate to reconstruct scorer from source code.
|
| model_validate_json(json_data: str) -> 'Scorer'
| Override model_validate_json to parse JSON and delegate to custom model_validate.
|
| Args:
| json_data: JSON string containing serialized scorer data.
|
| Returns:
| Scorer instance with correct subclass (BuiltInScorer, InstructionsJudge, etc.).
|
| Raises:
| mlflow.exceptions.MlflowException: If JSON parsing or scorer validation fails.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| filter_string
| Get the filter string for this scorer.
|
| .. Note:: Experimental: This property may change or be removed in a future release without warning.
|
| is_session_level_scorer
| Get whether this scorer is a session-level scorer.
|
| Defaults to False. Child classes can override this property to return True
| or compute the value dynamically based on their configuration.
|
| kind
|
| pass_if
| Predicate deciding whether this scorer's value counts as passing.
|
| Used by ``EvaluationResult.passed``. ``None`` means
| the default rule applies (a ``yes``/:class:`~mlflow.genai.judges.CategoricalRating`
| rating or a ``bool``). Set via ``@scorer(pass_if=...)``.
|
| sample_rate
| Get the sample rate for this scorer. Available when registered for monitoring.
|
| .. Note:: Experimental: This property may change or be removed in a future release without warning.
|
| status
| Get the status of this scorer, using only the local state.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset()
|
| __annotations__ = {'_cached_dump': dict[str, typing.Any] | None, '_exp...
|
| __class_vars__ = set()
|
| __private_attributes__ = {'_cached_dump': ModelPrivateAttr(), '_experi...
|
| __pydantic_complete__ = True
|
| __pydantic_computed_fields__ = {}
|
| __pydantic_core_schema__ = {'cls': <class 'mlflow.genai.scorers.base.S...
|
| __pydantic_custom_init__ = False
|
| __pydantic_decorators__ = DecoratorInfos(validators={}, field_validato...
|
| __pydantic_extra_info__ = None
|
| __pydantic_fields__ = {'aggregations': FieldInfo(annotation=Union[list...
|
| __pydantic_generic_metadata__ = {'args': (), 'origin': None, 'paramete...
|
| __pydantic_parent_namespace__ = None
|
| __pydantic_post_init__ = 'model_post_init'
|
| __pydantic_serializer__ = SchemaSerializer(serializer=PolymorphismTram...
|
| __pydantic_setattr_handlers__ = {}
|
| __pydantic_validator__ = SchemaValidator(title="Scorer", validator=Mod...
|
| __signature__ = <Signature (*, name: str, aggregations: list[typ... = ...
|
| model_config = {}
|
| ----------------------------------------------------------------------
| Methods inherited from pydantic.main.BaseModel:
|
| __copy__(self) -> 'Self'
| Returns a shallow copy of the model.
|
| __deepcopy__(self, memo: 'dict[int, Any] | None' = None) -> 'Self'
| Returns a deep copy of the model.
|
| __delattr__(self, item: 'str') -> 'Any'
| Implement delattr(self, name).
|
| __eq__(self, other: 'Any') -> 'bool'
| Return self==value.
|
| __getattr__(self, item: 'str') -> 'Any'
|
| __getstate__(self) -> 'dict[Any, Any]'
| Helper for pickle.
|
| __init__(self, /, **data: 'Any') -> 'None'
| Create a new model by parsing and validating input data from keyword arguments.
|
| Raises [`ValidationError`][pydantic_core.ValidationError] if the input data cannot be
| validated to form a valid model.
|
| `self` is explicitly positional-only to allow `self` as a field name.
|
| __iter__(self) -> 'TupleGenerator'
| So `dict(model)` works.
|
| __pretty__(self, fmt: 'Callable[[Any], Any]', **kwargs: 'Any') -> 'Generator[Any]' from pydantic._internal._repr.Representation
| Used by devtools (https://python-devtools.helpmanual.io/) to pretty print objects.
|
| __replace__(self, **changes: 'Any') -> 'Self'
| # Because we make use of `@dataclass_transform()`, `__replace__` is already synthesized by
| # type checkers, so we define the implementation in this `if not TYPE_CHECKING:` block:
|
| __repr_args__(self) -> '_repr.ReprArgs'
|
| __repr_name__(self) -> 'str' from pydantic._internal._repr.Representation
| Name of the instance's class, used in __repr__.
|
| __repr_recursion__(self, object: 'Any') -> 'str' from pydantic._internal._repr.Representation
| Returns the string representation of a recursive object.
|
| __repr_str__(self, join_str: 'str') -> 'str' from pydantic._internal._repr.Representation
|
| __rich_repr__(self) -> 'RichReprResult' from pydantic._internal._repr.Representation
| Used by Rich (https://rich.readthedocs.io/en/stable/pretty.html) to pretty print objects.
|
| __setattr__(self, name: 'str', value: 'Any') -> 'None'
| Implement setattr(self, name, value).
|
| __setstate__(self, state: 'dict[Any, Any]') -> 'None'
|
| __str__(self) -> 'str'
| Return str(self).
|
| copy(self, *, include: 'AbstractSetIntStr | MappingIntStrAny | None' = None, exclude: 'AbstractSetIntStr | MappingIntStrAny | None' = None, update: 'Dict[str, Any] | None' = None, deep: 'bool' = False) -> 'Self'
| Returns a copy of the model.
|
| !!! warning "Deprecated"
| This method is now deprecated; use `model_copy` instead.
|
| If you need `include` or `exclude`, use:
|
| ```python {test="skip" lint="skip"}
| data = self.model_dump(include=include, exclude=exclude, round_trip=True)
| data = {**data, **(update or {})}
| copied = self.model_validate(data)
| ```
|
| Args:
| include: Optional set or mapping specifying which fields to include in the copied model.
| exclude: Optional set or mapping specifying which fields to exclude in the copied model.
| update: Optional dictionary of field-value pairs to override field values in the copied model.
| deep: If True, the values of fields that are Pydantic models will be deep-copied.
|
| Returns:
| A copy of the model with included, excluded and updated fields as specified.
|
| dict(self, *, include: 'IncEx | None' = None, exclude: 'IncEx | None' = None, by_alias: 'bool' = False, exclude_unset: 'bool' = False, exclude_defaults: 'bool' = False, exclude_none: 'bool' = False) -> 'Dict[str, Any]'
|
| json(self, *, include: 'IncEx | None' = None, exclude: 'IncEx | None' = None, by_alias: 'bool' = False, exclude_unset: 'bool' = False, exclude_defaults: 'bool' = False, exclude_none: 'bool' = False, encoder: 'Callable[[Any], Any] | None' = PydanticUndefined, models_as_dict: 'bool' = PydanticUndefined, **dumps_kwargs: 'Any') -> 'str'
|
| model_copy(self, *, update: 'Mapping[str, Any] | None' = None, deep: 'bool' = False) -> 'Self'
| !!! abstract "Usage Documentation"
| [`model_copy`](../concepts/models.md#model-copy)
|
| Returns a copy of the model.
|
| !!! note
| The underlying instance's [`__dict__`][object.__dict__] attribute is copied. This
| might have unexpected side effects if you store anything in it, on top of the model
| fields (e.g. the value of [cached properties][functools.cached_property]).
|
| Args:
| update: Values to change/add in the new model. Note: the data is not validated
| before creating the new model. You should trust this data.
| deep: Set to `True` to make a deep copy of the model.
|
| Returns:
| New model instance.
|
| model_dump_json(self, *, indent: 'int | None' = None, ensure_ascii: 'bool' = False, include: 'IncEx | None' = None, exclude: 'IncEx | None' = None, context: 'Any | None' = None, by_alias: 'bool | None' = None, exclude_unset: 'bool' = False, exclude_defaults: 'bool' = False, exclude_none: 'bool' = False, exclude_computed_fields: 'bool' = False, round_trip: 'bool' = False, warnings: "bool | Literal['none', 'warn', 'error']" = True, fallback: 'Callable[[Any], Any] | None' = None, serialize_as_any: 'bool' = False, polymorphic_serialization: 'bool | None' = None) -> 'str'
| !!! abstract "Usage Documentation"
| [`model_dump_json`](../concepts/serialization.md#json-mode)
|
| Generates a JSON representation of the model using Pydantic's `to_json` method.
|
| Args:
| indent: Indentation to use in the JSON output. If None is passed, the output will be compact.
| ensure_ascii: If `True`, the output is guaranteed to have all incoming non-ASCII characters escaped.
| If `False` (the default), these characters will be output as-is.
| include: Field(s) to include in the JSON output.
| exclude: Field(s) to exclude from the JSON output.
| context: Additional context to pass to the serializer.
| by_alias: Whether to serialize using field aliases.
| exclude_unset: Whether to exclude fields that have not been explicitly set.
| exclude_defaults: Whether to exclude fields that are set to their default value.
| exclude_none: Whether to exclude fields that have a value of `None`.
| exclude_computed_fields: Whether to exclude computed fields.
| While this can be useful for round-tripping, it is usually recommended to use the dedicated
| `round_trip` parameter instead.
| round_trip: If True, dumped values should be valid as input for non-idempotent types such as Json[T].
| warnings: How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
| "error" raises a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError].
| fallback: A function to call when an unknown value is encountered. If not provided,
| a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError] error is raised.
| serialize_as_any: Whether to serialize fields with duck-typing serialization behavior.
| polymorphic_serialization: Whether to use model and dataclass polymorphic serialization for this call.
|
| Returns:
| A JSON string representation of the model.
|
| ----------------------------------------------------------------------
| Class methods inherited from pydantic.main.BaseModel:
|
| __class_getitem__(typevar_values: 'type[Any] | tuple[type[Any], ...]') -> 'type[BaseModel] | _forward_ref.PydanticRecursiveRef'
|
| __get_pydantic_core_schema__(source: 'type[BaseModel]', handler: 'GetCoreSchemaHandler', /) -> 'CoreSchema'
|
| __get_pydantic_json_schema__(core_schema: 'CoreSchema', handler: 'GetJsonSchemaHandler', /) -> 'JsonSchemaValue'
| Hook into generating the model's JSON schema.
|
| Args:
| core_schema: A `pydantic-core` CoreSchema.
| You can ignore this argument and call the handler with a new CoreSchema,
| wrap this CoreSchema (`{'type': 'nullable', 'schema': current_schema}`),
| or just call the handler with the original schema.
| handler: Call into Pydantic's internal JSON schema generation.
| This will raise a `pydantic.errors.PydanticInvalidForJsonSchema` if JSON schema
| generation fails.
| Since this gets called by `BaseModel.model_json_schema` you can override the
| `schema_generator` argument to that function to change JSON schema generation globally
| for a type.
|
| Returns:
| A JSON schema, as a Python object.
|
| __pydantic_init_subclass__(**kwargs: 'Any') -> 'None'
| This is intended to behave just like `__init_subclass__`, but is called by `ModelMetaclass`
| only after basic class initialization is complete. In particular, attributes like `model_fields` will
| be present when this is called, but forward annotations are not guaranteed to be resolved yet,
| meaning that creating an instance of the class may fail.
|
| This is necessary because `__init_subclass__` will always be called by `type.__new__`,
| and it would require a prohibitively large refactor to the `ModelMetaclass` to ensure that
| `type.__new__` was called in such a manner that the class would already be sufficiently initialized.
|
| This will receive the same `kwargs` that would be passed to the standard `__init_subclass__`, namely,
| any kwargs passed to the class definition that aren't used internally by Pydantic.
|
| Args:
| **kwargs: Any keyword arguments passed to the class definition that aren't used internally
| by Pydantic.
|
| Note:
| You may want to override [`__pydantic_on_complete__()`][pydantic.main.BaseModel.__pydantic_on_complete__]
| instead, which is called once the class and its fields are fully initialized and ready for validation.
|
| __pydantic_on_complete__() -> 'None'
| This is called once the class and its fields are fully initialized and ready to be used.
|
| This typically happens when the class is created (just before
| [`__pydantic_init_subclass__()`][pydantic.main.BaseModel.__pydantic_init_subclass__] is called on the superclass),
| except when forward annotations are used that could not immediately be resolved.
| In that case, it will be called later, when the model is rebuilt automatically or explicitly using
| [`model_rebuild()`][pydantic.main.BaseModel.model_rebuild].
|
| construct(_fields_set: 'set[str] | None' = None, **values: 'Any') -> 'Self'
|
| from_orm(obj: 'Any') -> 'Self'
|
| model_construct(_fields_set: 'set[str] | None' = None, **values: 'Any') -> 'Self'
| Creates a new instance of the `Model` class with validated data.
|
| Creates a new model setting `__dict__` and `__pydantic_fields_set__` from trusted or pre-validated data.
| Default values are respected, but no other validation is performed.
|
| !!! note
| `model_construct()` generally respects the `model_config.extra` setting on the provided model.
| That is, if `model_config.extra == 'allow'`, then all extra passed values are added to the model instance's `__dict__`
| and `__pydantic_extra__` fields. If `model_config.extra == 'ignore'` (the default), then all extra passed values are ignored.
| Because no validation is performed with a call to `model_construct()`, having `model_config.extra == 'forbid'` does not result in
| an error if extra values are passed, but they will be ignored.
|
| Args:
| _fields_set: A set of field names that were originally explicitly set during instantiation. If provided,
| this is directly used for the [`model_fields_set`][pydantic.BaseModel.model_fields_set] attribute.
| Otherwise, the field names from the `values` argument will be used.
| values: Trusted or pre-validated data dictionary.
|
| Returns:
| A new instance of the `Model` class with validated data.
|
| model_json_schema(by_alias: 'bool' = True, ref_template: 'str' = '#/$defs/{model}', schema_generator: 'type[GenerateJsonSchema]' = <class 'pydantic.json_schema.GenerateJsonSchema'>, mode: 'JsonSchemaMode' = 'validation', *, union_format: "Literal['any_of', 'primitive_type_array']" = 'any_of') -> 'dict[str, Any]'
| Generates a JSON schema for a model class.
|
| Args:
| by_alias: Whether to use attribute aliases or not.
| ref_template: The reference template.
| union_format: The format to use when combining schemas from unions together. Can be one of:
|
| - `'any_of'`: Use the [`anyOf`](https://json-schema.org/understanding-json-schema/reference/combining#anyOf)
| keyword to combine schemas (the default).
| - `'primitive_type_array'`: Use the [`type`](https://json-schema.org/understanding-json-schema/reference/type)
| keyword as an array of strings, containing each type of the combination. If any of the schemas is not a primitive
| type (`string`, `boolean`, `null`, `integer` or `number`) or contains constraints/metadata, falls back to
| `any_of`.
| schema_generator: To override the logic used to generate the JSON schema, as a subclass of
| `GenerateJsonSchema` with your desired modifications
| mode: The mode in which to generate the schema.
|
| Returns:
| The JSON schema for the given model class.
|
| model_parametrized_name(params: 'tuple[type[Any], ...]') -> 'str'
| Compute the class name for parametrizations of generic classes.
|
| This method can be overridden to achieve a custom naming scheme for generic BaseModels.
|
| Args:
| params: Tuple of types of the class. Given a generic class
| `Model` with 2 type variables and a concrete model `Model[str, int]`,
| the value `(str, int)` would be passed to `params`.
|
| Returns:
| String representing the new class where `params` are passed to `cls` as type variables.
|
| Raises:
| TypeError: Raised when trying to generate concrete names for non-generic models.
|
| model_rebuild(*, force: 'bool' = False, raise_errors: 'bool' = True, _parent_namespace_depth: 'int' = 2, _types_namespace: 'MappingNamespace | None' = None) -> 'bool | None'
| Try to rebuild the pydantic-core schema for the model.
|
| This may be necessary when one of the annotations is a ForwardRef which could not be resolved during
| the initial attempt to build the schema, and automatic rebuilding fails.
|
| Args:
| force: Whether to force the rebuilding of the model schema, defaults to `False`.
| raise_errors: Whether to raise errors, defaults to `True`.
| _parent_namespace_depth: The depth level of the parent namespace, defaults to 2.
| _types_namespace: The types namespace, defaults to `None`.
|
| Returns:
| Returns `None` if the schema is already "complete" and rebuilding was not required.
| If rebuilding _was_ required, returns `True` if rebuilding was successful, otherwise `False`.
|
| model_validate_strings(obj: 'Any', *, strict: 'bool | None' = None, extra: 'ExtraValues | None' = None, context: 'Any | None' = None, by_alias: 'bool | None' = None, by_name: 'bool | None' = None) -> 'Self'
| Validate the given object with string data against the Pydantic model.
|
| Args:
| obj: The object containing string data to validate.
| strict: Whether to enforce types strictly.
| extra: Whether to ignore, allow, or forbid extra data during model validation.
| See the [`extra` configuration value][pydantic.ConfigDict.extra] for details.
| context: Extra variables to pass to the validator.
| by_alias: Whether to use the field's alias when validating against the provided input data.
| by_name: Whether to use the field's name when validating against the provided input data.
|
| Returns:
| The validated Pydantic model.
|
| parse_file(path: 'str | Path', *, content_type: 'str | None' = None, encoding: 'str' = 'utf8', proto: 'DeprecatedParseProtocol | None' = None, allow_pickle: 'bool' = False) -> 'Self'
|
| parse_obj(obj: 'Any') -> 'Self'
|
| parse_raw(b: 'str | bytes', *, content_type: 'str | None' = None, encoding: 'str' = 'utf8', proto: 'DeprecatedParseProtocol | None' = None, allow_pickle: 'bool' = False) -> 'Self'
|
| schema(by_alias: 'bool' = True, ref_template: 'str' = '#/$defs/{model}') -> 'Dict[str, Any]'
|
| schema_json(*, by_alias: 'bool' = True, ref_template: 'str' = '#/$defs/{model}', **dumps_kwargs: 'Any') -> 'str'
|
| update_forward_refs(**localns: 'Any') -> 'None'
|
| validate(value: 'Any') -> 'Self'
|
| ----------------------------------------------------------------------
| Readonly properties inherited from pydantic.main.BaseModel:
|
| __fields_set__
|
| model_extra
| Get extra fields set during validation.
|
| Returns:
| A dictionary of extra fields, or `None` if `config.extra` is not set to `"allow"`.
|
| model_fields_set
| Returns the set of fields that have been explicitly set on this model instance.
|
| Returns:
| A set of strings representing the fields that have been set,
| i.e. that were not filled from defaults.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from pydantic.main.BaseModel:
|
| __dict__
| dictionary for instance variables
|
| __pydantic_extra__
|
| __pydantic_fields_set__
|
| __pydantic_private__
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from pydantic.main.BaseModel:
|
| __hash__ = None
|
| __pydantic_root_model__ = False
|
| model_computed_fields = {}
|
| model_fields = {'aggregations': FieldInfo(annotation=Union[list[Union[...
class ScorerScheduleConfig(builtins.object)
| ScorerScheduleConfig(scorer: mlflow.genai.scorers.base.Scorer, scheduled_scorer_name: str, sample_rate: float, filter_string: str | None = None) -> None
|
| A scheduled scorer configuration for automated monitoring of generative AI applications.
|
| Scheduled scorers are used to automatically evaluate traces logged to MLflow experiments
| by production applications. They are part of `Databricks Lakehouse Monitoring for GenAI
| <https://docs.databricks.com/aws/en/generative-ai/agent-evaluation/monitoring>`_,
| which helps track quality metrics like groundedness, safety, and guideline adherence
| alongside operational metrics like volume, latency, and cost.
|
| When configured, scheduled scorers run automatically in the background to evaluate
| a sample of traces based on the specified sampling rate and filter criteria. The
| Assessments are displayed in the Traces tab of the MLflow experiment and can be used to
| identify quality issues in production.
|
| Args:
| scorer: The scorer function to run on sampled traces. Must be either a built-in
| scorer (e.g., Safety, Correctness) or a function decorated with @scorer.
| Subclasses of Scorer are not supported.
| scheduled_scorer_name: The name for this scheduled scorer configuration
| within the experiment. This name must be unique among all scheduled scorers
| in the same experiment.
| We recommend using the scorer's name (e.g., scorer.name) for consistency.
| sample_rate: The fraction of traces to evaluate, between 0.0 and 1.0. For example,
| 0.1 means 10% of traces will be randomly selected for evaluation.
| filter_string: An optional MLflow search_traces compatible filter string to apply
| before sampling traces. Only traces matching this filter will be considered
| for evaluation. Uses the same syntax as mlflow.search_traces().
|
| Example:
| .. code-block:: python
|
| from mlflow.genai.scorers import Safety, scorer
| from mlflow.genai.scheduled_scorers import ScorerScheduleConfig
|
| # Using a built-in scorer
| safety_config = ScorerScheduleConfig(
| scorer=Safety(),
| scheduled_scorer_name="production_safety",
| sample_rate=0.2, # Evaluate 20% of traces
| filter_string="trace.status = 'OK'",
| )
|
|
| # Using a custom scorer
| @scorer
| def response_length(outputs):
| return len(str(outputs)) > 100
|
|
| length_config = ScorerScheduleConfig(
| scorer=response_length,
| scheduled_scorer_name="adequate_length",
| sample_rate=0.1, # Evaluate 10% of traces
| filter_string="trace.status = 'OK'",
| )
|
| Note:
| Scheduled scorers are executed automatically by Databricks and do not need to be
| manually triggered. The Assessments appear in the Traces tab of the MLflow
| experiment. Only traces logged directly to the experiment are monitored; traces
| logged to individual runs within the experiment are not evaluated.
|
| .. warning::
| This API is in Beta and may change or be removed in a future release without warning.
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, scorer: mlflow.genai.scorers.base.Scorer, scheduled_scorer_name: str, sample_rate: float, filter_string: str | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'filter_string': str | None, 'sample_rate': <class ...
|
| __dataclass_fields__ = {'filter_string': Field(name='filter_string',ty...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('scorer', 'scheduled_scorer_name', 'sample_rate', 'f...
|
| filter_string = None
FUNCTIONS
create_dataset(name: str | None = None, experiment_id: str | list[str] | None = None, tags: dict[str, typing.Any] | None = None) -> 'EvaluationDataset'
.. Note:: Parameter ``uc_table_name`` is deprecated. Use ``name`` instead.
Create a dataset with the given name and associate it with the given experiment.
Args:
name: The name of the dataset. In Databricks, this is the UC table name.
experiment_id: The ID of the experiment(s) to associate the dataset with. If not provided,
the current experiment is inferred from the environment.
tags: Dictionary of tags to apply to the dataset. Not supported in Databricks.
Returns:
An EvaluationDataset object representing the created dataset.
Examples:
.. code-block:: python
from mlflow.genai.datasets import create_dataset
# Create a dataset with a single experiment
dataset = create_dataset(
name="customer_support_qa_v1",
experiment_id="0", # Default experiment
tags={
"version": "1.0",
"purpose": "regression_testing",
"model": "gpt-4",
"team": "ml-platform",
},
)
print(f"Created dataset: {dataset.dataset_id}")
# Output: Created dataset: d-1a2b3c4d5e6f7890abcdef1234567890
# Create a dataset linked to multiple experiments
multi_exp_dataset = create_dataset(
name="cross_team_eval_dataset",
experiment_id=["1", "2", "5"], # Multiple experiment IDs
tags={
"coverage": "comprehensive",
"status": "development",
},
)
# Create a dataset without tags (minimal example)
simple_dataset = create_dataset(
name="quick_test_dataset",
experiment_id="3", # Specific experiment
)
create_labeling_session(name: str, *, assigned_users: list[str] | None = None, agent: str | None = None, label_schemas: list[str] | None = None, enable_multi_turn_chat: bool = False, custom_inputs: dict[str, typing.Any] | None = None) -> mlflow.genai.labeling.labeling.LabelingSession
Create a new labeling session in the review app.
.. note::
This functionality is only available in Databricks. Please run
`pip install mlflow[databricks]` to use it.
Args:
name: The name of the labeling session.
assigned_users: The users that will be assigned to label items in the session.
agent: The agent to be used to generate responses for the items in the session.
label_schemas: The label schemas to be used in the session.
enable_multi_turn_chat: Whether to enable multi-turn chat labeling for the session.
custom_inputs: Optional. Custom inputs to be used in the session.
Returns:
LabelingSession: The created labeling session.
create_mcp_access_endpoint(server_name: 'str', url: 'str', transport_type: "Literal['streamable-http', 'sse']" = 'streamable-http', server_version: 'str | None' = None, server_alias: 'str | None' = None) -> 'MCPAccessEndpoint'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Record an approved direct-access endpoint for an MCP server.
Exactly one of ``server_version`` or ``server_alias`` must be provided.
Args:
server_name: Server name.
url: URL of the remote MCP endpoint.
transport_type: Transport protocol — ``"streamable-http"`` (default) or ``"sse"``.
server_version: Pin the endpoint to a specific version string.
server_alias: Pin the endpoint to an alias.
Returns:
The created :py:class:`MCPAccessEndpoint <mlflow.entities.MCPAccessEndpoint>`.
Example:
.. code-block:: python
import mlflow
endpoint = mlflow.genai.create_mcp_access_endpoint(
server_name="io.github.anthropic/brave-search",
url="https://mcp.acme.internal/brave-search",
transport_type="streamable-http",
server_alias="production",
)
delete_dataset(name: str | None = None, dataset_id: str | None = None) -> None
.. Note:: Parameter ``uc_table_name`` is deprecated. Use ``name`` instead.
Delete a dataset.
Args:
name: The name of the dataset (Databricks only). In Databricks, this is the UC table name.
dataset_id: The ID of the dataset.
Note:
- In Databricks environments: Use 'name' to specify the dataset.
- Outside of Databricks: Use 'dataset_id' to specify the dataset
Examples:
.. code-block:: python
from mlflow.genai.datasets import delete_dataset, search_datasets
# Delete a specific dataset by ID (non-Databricks)
delete_dataset(dataset_id="d-4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e")
# Clean up old test datasets
test_datasets = search_datasets(
filter_string="name LIKE 'test_%' AND tags.environment = 'development'",
order_by=["created_time ASC"],
)
# Delete datasets older than the most recent 5
if len(test_datasets) > 5:
for dataset in test_datasets[:-5]: # Keep the 5 most recent
print(f"Deleting old test dataset: {dataset.name}")
delete_dataset(dataset_id=dataset.dataset_id)
# Delete datasets with specific criteria
deprecated_datasets = search_datasets(filter_string="tags.status = 'deprecated'")
for dataset in deprecated_datasets:
delete_dataset(dataset_id=dataset.dataset_id)
print(f"Deleted deprecated dataset: {dataset.name}")
.. warning::
Deleting a dataset is permanent and cannot be undone. All associated
records, tags, and metadata will be permanently removed.
delete_dataset_tag(dataset_id: str, key: str) -> None
Delete a tag from a dataset.
Args:
dataset_id: The ID of the dataset.
key: The tag key to delete.
Examples:
.. code-block:: python
from mlflow.genai.datasets import delete_dataset_tag, get_dataset
# Get your dataset
dataset = get_dataset(dataset_id="d-9e8f7c6b5a4d3e2f1a0b9c8d7e6f5a4b")
# Remove a single tag
delete_dataset_tag(dataset_id=dataset.dataset_id, key="deprecated")
# Remove outdated tags during cleanup
outdated_tags = ["old_version", "temp_flag", "development_only"]
for tag_key in outdated_tags:
delete_dataset_tag(dataset_id=dataset.dataset_id, key=tag_key)
# Check remaining tags
updated_dataset = get_dataset(dataset_id=dataset.dataset_id)
print(f"Remaining tags: {updated_dataset.tags}")
Note:
This API is not available in Databricks environments yet.
Tags in Databricks are managed through Unity Catalog.
delete_labeling_session(labeling_session: mlflow.genai.labeling.labeling.LabelingSession)
Delete a labeling session from the review app.
.. note::
This functionality is only available in Databricks. Please run
`pip install mlflow[databricks]` to use it.
Args:
labeling_session: The labeling session to delete.
delete_mcp_access_endpoint(server_name: 'str', endpoint_id: 'str') -> 'None'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
delete_mcp_server(name: 'str') -> 'None'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Delete an MCP server and all its child entities.
Deletion is rejected while any version of the server is still ``ACTIVE``.
Args:
name: Server name.
delete_mcp_server_alias(name: 'str', alias: 'str') -> 'None'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
delete_mcp_server_tag(name: 'str', key: 'str') -> 'None'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
delete_mcp_server_version(name: 'str', version: 'str') -> 'None'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
delete_mcp_server_version_tag(name: 'str', version: 'str', key: 'str') -> 'None'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
delete_prompt_alias(name: str, alias: str) -> None
Delete an alias for a :py:class:`Prompt <mlflow.entities.Prompt>` in the MLflow Prompt Registry.
Args:
name: The name of the prompt.
alias: The alias to delete for the prompt.
delete_prompt_model_config(name: str, version: str | int) -> None
Delete the model configuration from a specific prompt version.
Args:
name: The name of the prompt.
version: The version of the prompt.
Example:
.. code-block:: python
import mlflow
# Remove model config from a prompt version
mlflow.genai.delete_prompt_model_config(name="my-prompt", version=1)
# Verify the config was removed
prompt = mlflow.genai.load_prompt("my-prompt", version=1)
assert prompt.model_config is None
delete_prompt_tag(name: str, key: str) -> None
Delete a tag from a prompt in the MLflow Prompt Registry.
Args:
name: The name of the prompt.
key: The key of the tag
delete_prompt_version_tag(name: str, version: str | int, key: str) -> None
Delete a tag from a prompt version in the MLflow Prompt Registry.
Args:
name: The name of the prompt.
version: The version of the prompt.
key: The key of the tag
delete_scorer(*, name: str, experiment_id: str | None = None, version: int | str | None = None) -> None
Delete a registered scorer from the MLflow experiment.
This function permanently removes scorer registrations.
The behavior of this function varies depending on the backend store and version parameter:
**OSS MLflow Tracking Backend:**
- Supports versioning with granular deletion options
- Can delete specific versions or all versions of a scorer by setting `version`
parameter to "all"
**Databricks Backend:**
- Does not support versioning
- Deletes the entire scorer regardless of version parameter
- `version` parameter must be None
Args:
name (str): The name of the scorer to delete. This must match exactly with the
name used during scorer registration.
experiment_id (str, optional): The ID of the MLflow experiment containing the scorer.
If None, uses the currently active experiment as determined by
:func:`mlflow.get_experiment_by_name` or :func:`mlflow.set_experiment`.
version (int | str | None, optional): The version(s) to delete:
For OSS MLflow tracking backend: if `None`, deletes the latest version only, if version
is an integer, deletes the specific version, if version is the string 'all', deletes
all versions of the scorer
For Databricks backend, the version must be set to `None` (versioning not supported)
Raises:
mlflow.MlflowException: If the scorer with the specified name is not found in
the experiment, if the specified version doesn't exist, or if versioning
is not supported for the current backend.
Example:
.. code-block:: python
from mlflow.genai.scorers import delete_scorer
# Delete the latest version of a scorer from current experiment
delete_scorer(name="accuracy_scorer")
# Delete a specific version of a scorer
delete_scorer(name="safety_scorer", version=2)
# Delete all versions of a scorer
delete_scorer(name="relevance_scorer", version="all")
# Delete a scorer from a specific experiment
delete_scorer(name="harmfulness_scorer", experiment_id="123", version=1)
disable_git_model_versioning() -> None
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Disable Git-based model versioning and clear the active model context.
This function stops automatic Git-based version tracking and clears any active
LoggedModel context. After calling this, traces will no longer be automatically
linked to Git-based versions.
This is automatically called when exiting a context manager created with
enable_git_model_versioning().
Example:
.. code-block:: python
import mlflow.genai
# Enable versioning
context = mlflow.genai.enable_git_model_versioning()
# ... do work with versioning enabled ...
# Disable versioning
mlflow.genai.disable_git_model_versioning()
# Traces are no longer linked to Git versions
enable_git_model_versioning(remote_name: str = 'origin') -> mlflow.genai.git_versioning.GitContext
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Enable automatic Git-based model versioning for MLflow traces.
This function enables automatic version tracking based on your Git repository state.
When enabled, MLflow will:
- Detect the current Git branch, commit hash, and dirty state
- Create or reuse a LoggedModel matching this exact Git state
- Link all subsequent traces to this LoggedModel version
- Capture uncommitted changes as diffs when the repository is dirty
Args:
remote_name: The name of the git remote to use for repository URL detection.
Defaults to "origin".
Returns:
A GitContext instance containing:
- info: GitInfo object with branch, commit, dirty state, and diff information
- active_model: The active LoggedModel linked to current Git state
Example:
.. code-block:: python
import mlflow.genai
# Enable Git-based versioning
context = mlflow.genai.enable_git_model_versioning()
print(f"Branch: {context.info.branch}, Commit: {context.info.commit[:8]}")
# Output: Branch: main, Commit: abc12345
# All traces are now automatically linked to this Git version
@mlflow.trace
def my_app():
return "result"
# Can also use as a context manager
with mlflow.genai.enable_git_model_versioning() as context:
# Traces within this block are linked to the Git version
result = my_app()
Note:
If Git is not available or the current directory is not a Git repository,
a warning is issued and versioning is disabled (context.info will be None).
evaluate(data: 'EvaluationDatasetTypes', scorers: list[mlflow.genai.scorers.base.Scorer], predict_fn: Optional[Callable[..., Any]] = None, model_id: str | None = None) -> 'EvaluationResult'
Evaluate the performance of a generative AI model/application using specified
data and scorers.
This function allows you to evaluate a model's performance on a given dataset
using various scoring criteria. It supports both built-in scorers provided by
MLflow and custom scorers. The evaluation results include metrics and detailed
per-row assessments.
There are three different ways to use this function:
**1. Use Traces to evaluate the model/application.**
The `data` parameter takes a DataFrame with `trace` column, which contains a
single trace object corresponding to the prediction for the row. This dataframe
is easily obtained from the existing traces stored in MLflow, by using the
:py:func:`mlflow.search_traces` function.
.. code-block:: python
import mlflow
from mlflow.genai.scorers import Correctness, Safety
import pandas as pd
# model_id is a string starting with "m-", e.g. "m-074689226d3b40bfbbdf4c3ff35832cd"
trace_df = mlflow.search_traces(model_id="<my-model-id>")
mlflow.genai.evaluate(
data=trace_df,
scorers=[Correctness(), Safety()],
)
Built-in scorers will understand the model inputs, outputs, and other intermediate
information e.g. retrieved context, from the trace object. You can also access to
the trace object from the custom scorer function by using the `trace` parameter.
.. code-block:: python
from mlflow.genai.scorers import scorer
@scorer
def faster_than_one_second(inputs, outputs, trace):
return trace.info.execution_duration < 1000
**2. Use DataFrame or dictionary with "inputs", "outputs", "expectations" columns.**
Alternatively, you can pass inputs, outputs, and expectations (ground truth) as
a column in the dataframe (or equivalent list of dictionaries).
.. code-block:: python
import mlflow
from mlflow.genai.scorers import Correctness
import pandas as pd
data = pd.DataFrame([
{
"inputs": {"question": "What is MLflow?"},
"outputs": "MLflow is an ML platform",
"expectations": "MLflow is an ML platform",
},
{
"inputs": {"question": "What is Spark?"},
"outputs": "I don't know",
"expectations": "Spark is a data engine",
},
])
mlflow.genai.evaluate(
data=data,
scorers=[Correctness()],
)
**3. Pass `predict_fn` and input samples (and optionally expectations).**
If you want to generate the outputs and traces on-the-fly from your input samples,
you can pass a callable to the `predict_fn` parameter. In this case, MLflow will
pass the inputs to the `predict_fn` as keyword arguments. Therefore, the "inputs"
column must be a dictionary with the parameter names as keys.
.. code-block:: python
import mlflow
from mlflow.genai.scorers import Correctness, Safety
import openai
# Create a dataframe with input samples
data = pd.DataFrame([
{"inputs": {"question": "What is MLflow?"}},
{"inputs": {"question": "What is Spark?"}},
])
# Define a predict function to evaluate. The "inputs" column will be
# passed to the prediction function as keyword arguments.
def predict_fn(question: str) -> str:
response = openai.OpenAI().chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": question}],
)
return response.choices[0].message.content
mlflow.genai.evaluate(
data=data,
predict_fn=predict_fn,
scorers=[Correctness(), Safety()],
)
**4. Pass a ConversationSimulator for multi-turn evaluation.**
For multi-turn evaluation, you can pass a ConversationSimulator to the `data`
parameter along with a `predict_fn`. The simulator will generate conversations
by simulating user interactions with your agent, and the resulting traces will
be evaluated.
The `predict_fn` must follow the OpenAI Responses API format
(https://platform.openai.com/docs/api-reference/responses):
- It must accept an ``input`` parameter containing the conversation history
as a list of message dictionaries (e.g., ``[{"role": "user", "content": "..."}]``)
- It may accept additional keyword arguments from the test case's ``context`` field
- It should return a response (the assistant's message content will be extracted)
.. code-block:: python
import mlflow
from mlflow.genai.simulators import ConversationSimulator
from mlflow.genai.scorers import Safety
simulator = ConversationSimulator(
test_cases=[
{
"goal": "Learn about MLflow tracking",
"persona": "A beginner",
"context": {"user_id": "123"}, # passed as kwargs to predict_fn
},
],
max_turns=3,
)
def predict_fn(input: list[dict], **kwargs) -> dict:
# input is the conversation history: [{"role": "user", "content": "..."}, ...]
# kwargs contains context from test case (e.g., user_id="123")
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=input,
)
return response
mlflow.genai.evaluate(
data=simulator,
predict_fn=predict_fn,
scorers=[Safety()],
)
Args:
data: Dataset for the evaluation. Must be one of the following formats:
* An EvaluationDataset entity
* Pandas DataFrame
* Spark DataFrame
* List of dictionaries
* List of `Trace` objects
* A ConversationSimulator (requires `predict_fn`)
The dataset must include either of the following columns:
1. `trace` column that contains a single trace object corresponding
to the prediction for the row.
If this column is present, MLflow extracts inputs, outputs, assessments,
and other intermediate information e.g. retrieved context, from the trace
object and uses them for scoring. When this column is present, the
`predict_fn` parameter must not be provided.
2. `inputs`, `outputs`, `expectations` columns.
Alternatively, you can pass inputs, outputs, and expectations(ground
truth) as a column in the dataframe (or equivalent list of dictionaries).
- inputs (required): Column containing inputs for evaluation. The value
must be a dictionary. When `predict_fn` is provided, MLflow will pass
the inputs to the `predict_fn` as keyword arguments. For example,
* predict_fn: `def predict_fn(question: str, context: str) -> str`
* inputs: `{"question": "What is MLflow?", "context": "MLflow is an ML platform"}`
* `predict_fn` will receive "What is MLflow?" as the first argument
(`question`) and "MLflow is an ML platform" as the second argument (`context`)
- outputs (optional): Column containing model or app outputs.
If this column is present, `predict_fn` must not be provided.
- expectations (optional): Column containing a dictionary of ground truths.
For list of dictionaries, each dict should follow the above schema.
Optional columns:
- tags (optional): Column containing a dictionary of tags. The tags will be logged
to the respective traces.
scorers: A list of Scorer objects that produces evaluation scores from
inputs, outputs, and other additional contexts. MLflow provides pre-defined
scorers, but you can also define custom ones.
predict_fn: The target function to be evaluated. The specified function will be
executed for each row in the input dataset, and outputs will be used for
scoring.
The function must emit a single trace per call. If it doesn't, decorate
the function with @mlflow.trace decorator to ensure a trace to be emitted.
Both synchronous and asynchronous (async def) functions are supported. Async
functions are automatically detected and wrapped to run synchronously with a
configurable timeout (default: 300 seconds). Set the timeout using the
MLFLOW_GENAI_EVAL_ASYNC_TIMEOUT environment variable.
model_id: Optional model identifier (e.g. "m-074689226d3b40bfbbdf4c3ff35832cd")
to associate with the evaluation results. Can be also set globally via the
:py:func:`mlflow.set_active_model` function.
Returns:
An :py:class:`mlflow.genai.evaluation.entities.EvaluationResult` object.
Note:
Certain advanced features of this function are only supported on Databricks.
The tracking URI must be set to Databricks to use these features.
.. warning::
This function is not thread-safe. Please do not use it in multi-threaded
environments.
get_dataset(name: str | None = None, dataset_id: str | None = None) -> 'EvaluationDataset'
.. Note:: Parameter ``uc_table_name`` is deprecated. Use ``name`` instead.
Get the dataset with the given name or ID.
Args:
name: The name of the dataset. In Databricks, this is the UC table name.
In non-Databricks environments, this will search for a dataset with the given name.
dataset_id: The ID of the dataset (non-Databricks only).
Returns:
An EvaluationDataset object representing the retrieved dataset.
Note:
- In Databricks environments: Use 'name' to specify the dataset.
- Outside of Databricks: Use either 'name' or 'dataset_id' to specify the dataset.
If using 'name', the dataset name must be unique; otherwise use 'dataset_id'.
Examples:
.. code-block:: python
from mlflow.genai.datasets import get_dataset
# Get a dataset by name
dataset = get_dataset(name="my_evaluation_dataset")
# Get a dataset by ID
dataset = get_dataset(dataset_id="d-7f2e3a9b8c1d4e5f6a7b8c9d0e1f2a3b")
# Access dataset properties
print(f"Dataset name: {dataset.name}")
print(f"Tags: {dataset.tags}")
print(f"Created by: {dataset.created_by}")
# Work with the dataset
df = dataset.to_df() # Convert to pandas DataFrame
schema = dataset.schema # Get auto-computed schema
profile = dataset.profile # Get dataset statistics
# Add new records to the dataset
new_test_cases = [
{
"inputs": {"question": "What is MLflow?"},
"expectations": {"accuracy": 0.95, "contains_tracking": True},
}
]
dataset.merge_records(new_test_cases)
get_labeling_session(run_id: str) -> mlflow.genai.labeling.labeling.LabelingSession
Get a labeling session from the review app.
.. note::
This functionality is only available in Databricks. Please run
`pip install mlflow[databricks]` to use it.
Args:
run_id: The mlflow run ID of the labeling session to get.
Returns:
LabelingSession: The labeling session.
get_labeling_sessions() -> list[mlflow.genai.labeling.labeling.LabelingSession]
Get all labeling sessions from the review app.
.. note::
This functionality is only available in Databricks. Please run
`pip install mlflow[databricks]` to use it.
Returns:
list[LabelingSession]: The list of labeling sessions.
get_latest_mcp_server_version(name: 'str') -> 'MCPServerVersion'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Get the latest version of an MCP server.
Resolves using semantic-version ordering: highest semver among ACTIVE versions
if one exists, otherwise highest semver among non-DELETED versions.
Args:
name: Server name.
Returns:
The latest :py:class:`MCPServerVersion <mlflow.entities.MCPServerVersion>`.
get_mcp_access_endpoint(server_name: 'str', endpoint_id: 'str') -> 'MCPAccessEndpoint'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
get_mcp_server(name: 'str') -> 'MCPServer'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Get an MCP server by name.
Args:
name: Server name.
Returns:
The :py:class:`MCPServer <mlflow.entities.MCPServer>` with tags, aliases, and
access endpoints populated.
get_mcp_server_version(name: 'str', version: 'str') -> 'MCPServerVersion'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
get_mcp_server_version_by_alias(name: 'str', alias: 'str') -> 'MCPServerVersion'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Resolve an alias to an MCP server version.
The reserved alias ``"latest"`` delegates to latest-version resolution logic.
Args:
name: Server name.
alias: Alias name (e.g., ``"production"``).
Returns:
The :py:class:`MCPServerVersion <mlflow.entities.MCPServerVersion>`.
get_prompt_tags(name: str) -> mlflow.entities.model_registry.prompt.Prompt
Get a prompt's metadata from the MLflow Prompt Registry.
Args:
name: The name of the prompt.
get_review_app(experiment_id: str | None = None) -> 'ReviewApp'
Gets or creates (if it doesn't exist) the review app for the given experiment ID.
.. note::
This functionality is only available in Databricks. Please run
`pip install mlflow[databricks]` to use it.
Args:
experiment_id: Optional. The experiment ID for which to get the review app. If not provided,
the experiment ID is inferred from the current active environment.
Returns:
ReviewApp: The review app.
get_scorer(*, name: str, experiment_id: str | None = None, version: int | None = None) -> mlflow.genai.scorers.base.Scorer
Retrieve a specific registered scorer by name and optional version.
This function retrieves a single Scorer instance from the specified experiment. If no
version is specified, it returns the latest (highest version number) scorer with the
given name.
Args:
name (str): The name of the registered scorer to retrieve. This must match exactly
with the name used during scorer registration.
experiment_id (str, optional): The ID of the MLflow experiment containing the scorer.
If None, uses the currently active experiment as determined by
:func:`mlflow.get_experiment_by_name` or :func:`mlflow.set_experiment`.
version (int, optional): The specific version of the scorer to retrieve. If None,
returns the scorer with the highest version number (latest version).
Returns:
Scorer: A Scorer object representing the requested scorer.
Raises:
mlflow.MlflowException: If the scorer with the specified name is not found in the
experiment, if the specified version doesn't exist, if the experiment doesn't exist,
or if there are issues with the backend store connection.
Example:
.. code-block:: python
from mlflow.genai.scorers import get_scorer
# Get the latest version of a scorer
latest_scorer = get_scorer(name="accuracy_scorer")
# Get a specific version of a scorer
v2_scorer = get_scorer(name="safety_scorer", version=2)
# Get a scorer from a specific experiment
scorer = get_scorer(name="relevance_scorer", experiment_id="123")
Note:
- When no version is specified, the function automatically returns the latest version
- This function works with both OSS MLflow tracking backend and Databricks backend.
- For Databricks backend, versioning is not supported, so the version parameter
should be None.
list_scorers(*, experiment_id: str | None = None) -> list[mlflow.genai.scorers.base.Scorer]
List all registered scorers for an experiment.
This function retrieves all scorers that have been registered in the specified experiment.
For each scorer name, only the latest version is returned.
The function automatically determines the appropriate backend store (MLflow tracking store,
Databricks, etc.) based on the current MLflow configuration and experiment location.
Args:
experiment_id (str, optional): The ID of the MLflow experiment containing the scorers.
If None, uses the currently active experiment as determined by
:func:`mlflow.get_experiment_by_name` or :func:`mlflow.set_experiment`.
Returns:
list[Scorer]: A list of Scorer objects, each representing the latest version of a
registered scorer with its current configuration. The list may be empty if no
scorers have been registered in the experiment.
Raises:
mlflow.MlflowException: If the experiment doesn't exist or if there are issues with
the backend store connection.
Example:
.. code-block:: python
from mlflow.genai.scorers import list_scorers
# List all scorers in the current experiment
scorers = list_scorers()
# List all scorers in a specific experiment
scorers = list_scorers(experiment_id="123")
# Process the returned scorers
for scorer in scorers:
print(f"Scorer: {scorer.name}")
Note:
- Only the latest version of each scorer is returned.
- This function works with both OSS MLflow tracking backend and Databricks backend.
load_prompt(name_or_uri: str, version: str | int | None = None, allow_missing: bool = False, link_to_model: bool = True, model_id: str | None = None, cache_ttl_seconds: float | None = None) -> mlflow.entities.model_registry.prompt_version.PromptVersion
Load a :py:class:`Prompt <mlflow.entities.Prompt>` from the MLflow Prompt Registry.
The prompt can be specified by name and version, or by URI.
Args:
name_or_uri: The name of the prompt, or the URI in the format "prompts:/name/version".
version: The version of the prompt (required when using name, not allowed when using URI).
allow_missing: If True, return None instead of raising Exception if the specified prompt
is not found.
link_to_model: If True, link the prompt to the model.
model_id: The ID of the model to link the prompt to. Only used if link_to_model is True.
cache_ttl_seconds: Time-to-live in seconds for the cached prompt. If not specified,
uses the value from `MLFLOW_ALIAS_PROMPT_CACHE_TTL_SECONDS` environment variable for
alias-based prompts (default 60), and the value from
`MLFLOW_VERSION_PROMPT_CACHE_TTL_SECONDS` environment variable for version-based prompts
(default None, no TTL).
Set to 0 to bypass the cache and always fetch from the server.
Example:
.. code-block:: python
import mlflow
# Load the latest version of the prompt
prompt = mlflow.genai.load_prompt("my_prompt")
# Load a specific version of the prompt
prompt = mlflow.genai.load_prompt("my_prompt", version=1)
# Load a specific version of the prompt by URI
prompt = mlflow.genai.load_prompt("prompts:/my_prompt/1")
# Load a prompt version with an alias "production"
prompt = mlflow.genai.load_prompt("prompts:/my_prompt@production")
# Load the latest version of the prompt by URI
prompt = mlflow.genai.load_prompt("prompts:/my_prompt@latest")
# Load with custom cache TTL (5 minutes)
prompt = mlflow.genai.load_prompt("my_prompt", version=1, cache_ttl_seconds=300)
# Bypass cache entirely
prompt = mlflow.genai.load_prompt("my_prompt", version=1, cache_ttl_seconds=0)
make_judge(name: str, instructions: str, model: str | None = None, description: str | None = None, feedback_value_type: Any = None, inference_params: dict[str, typing.Any] | None = None, base_url: str | None = None, extra_headers: dict[str, str] | None = None, include_timing_in_conversation: bool = False) -> mlflow.genai.judges.base.Judge
Create a custom MLflow judge instance.
Args:
name: The name of the judge
instructions: Natural language instructions for evaluation. Must contain at least one
template variable: {{ inputs }}, {{ outputs }}, {{ expectations }},
{{ conversation }}, or {{ trace }} to reference evaluation data. Custom
variables are not supported.
Note: {{ conversation }} can only coexist with {{ expectations }}.
It cannot be used together with {{ inputs }}, {{ outputs }}, or {{ trace }}.
model: The model identifier to use for evaluation (e.g., "openai:/gpt-4")
description: A description of what the judge evaluates
feedback_value_type: Type specification for the 'value' field in the Feedback
object. The judge will use structured outputs to enforce this type.
If unspecified, the feedback value type is determined by the judge.
It is recommended to explicitly specify the type.
Supported types (matching FeedbackValueType):
- int: Integer ratings (e.g., 1-5 scale)
- float: Floating point scores (e.g., 0.0-1.0)
- str: Text responses
- bool: Yes/no evaluations
- T | None / Optional[T]: Nullable primitive (e.g., ``float | None``
for a score that may be absent)
- Literal[values]: Enum-like choices (e.g., Literal["good", "bad"])
- dict[str, int | float | str | bool]: Dictionary with string keys and
int, float, str, or bool values.
- list[int | float | str | bool]: List of int, float, str, or bool values
Note: Pydantic BaseModel types are not supported.
inference_params: Optional dictionary of inference parameters to pass to the model
(e.g., temperature, top_p, max_tokens). These parameters allow
fine-grained control over the model's behavior during evaluation.
For example, setting a lower temperature can produce more
deterministic and reproducible evaluation results.
base_url: Optional base URL to route requests through. When specified, all
requests to the LLM provider will be routed through this URL.
This is useful when LLM access must go through an internal gateway,
security proxy, or custom API endpoint.
Not supported for Databricks-backed models (including Databricks
endpoints, the default managed judge model, or "databricks:/..."
model URIs).
extra_headers: Optional dictionary of additional HTTP headers to include in
requests to the LLM provider. Can be used for authentication,
tracking, or other custom requirements.
Not supported for Databricks-backed models (including Databricks
endpoints, the default managed judge model, or "databricks:/..."
model URIs).
include_timing_in_conversation: If True, append timing information (duration and
slowest spans) to assistant responses when evaluating conversations.
Useful for latency-aware evaluation. Default is False for backward
compatibility. Only applies when using {{ conversation }} template variable.
Returns:
An InstructionsJudge instance configured with the provided parameters
Example:
.. code-block:: python
import mlflow
from mlflow.genai.judges import make_judge
from typing import Literal
# Create a judge that evaluates response quality using template variables
quality_judge = make_judge(
name="response_quality",
instructions=(
"Evaluate if the response in {{ outputs }} correctly answers "
"the question in {{ inputs }}. The response should be accurate, "
"complete, and professional."
),
model="openai:/gpt-4",
feedback_value_type=Literal["yes", "no"],
)
# Evaluate a response
result = quality_judge(
inputs={"question": "What is machine learning?"},
outputs="ML is basically when computers learn stuff on their own",
)
# Create a judge that compares against expectations
correctness_judge = make_judge(
name="correctness",
instructions=(
"Compare the {{ outputs }} against the {{ expectations }}. "
"Rate how well they match on a scale of 1-5."
),
model="openai:/gpt-4",
feedback_value_type=int,
)
# Evaluate with expectations (must be dictionaries)
result = correctness_judge(
inputs={"question": "What is the capital of France?"},
outputs={"answer": "The capital of France is Paris."},
expectations={"expected_answer": "Paris"},
)
# Create a judge that evaluates based on trace context
trace_judge = make_judge(
name="trace_quality",
instructions="Evaluate the overall quality of the {{ trace }} execution.",
model="openai:/gpt-4",
feedback_value_type=Literal["good", "needs_improvement"],
)
# Use with search_traces() - evaluate each trace
traces = mlflow.search_traces(locations=["1"], return_type="list")
for trace in traces:
feedback = trace_judge(trace=trace)
print(f"Trace {trace.info.trace_id}: {feedback.value} - {feedback.rationale}")
# Create a multi-turn judge that detects user frustration
frustration_judge = make_judge(
name="user_frustration",
instructions=(
"Analyze the {{ conversation }} to detect signs of user frustration. "
"Look for indicators such as repeated questions, negative language, "
"or expressions of dissatisfaction."
),
model="openai:/gpt-4",
feedback_value_type=Literal["frustrated", "not frustrated"],
)
# Evaluate a multi-turn conversation using session traces
session = mlflow.search_traces(
locations=["1"],
filter_string="metadata.`mlflow.trace.session` = 'session_123'",
return_type="list",
)
result = frustration_judge(session=session)
# Align a judge with human feedback
aligned_judge = quality_judge.align(traces)
# To see detailed optimization output during alignment, enable DEBUG logging:
# import logging
# logging.getLogger("mlflow.genai.judges.optimizers.memalign").setLevel(logging.DEBUG)
optimize_prompt(*args, **kwargs)
optimize_prompts(*, predict_fn: Callable[..., Any], train_data: 'EvaluationDatasetTypes', prompt_uris: list[str], optimizer: mlflow.genai.optimize.optimizers.base.BasePromptOptimizer, scorers: list[mlflow.genai.scorers.base.Scorer] | None = None, aggregation: Optional[Callable[[dict[str, bool | float | str | mlflow.entities.assessment.Feedback | list[mlflow.entities.assessment.Feedback]]], float]] = None, enable_tracking: bool = True) -> mlflow.genai.optimize.types.PromptOptimizationResult
Automatically optimize prompts using evaluation metrics and training data.
This function uses the provided optimization algorithm to improve prompt
quality based on your evaluation criteria and dataset.
Args:
predict_fn: a target function that uses the prompts to be optimized.
The callable should receive inputs as keyword arguments and
return the response. The function should use MLflow prompt registry
and call `PromptVersion.format` during execution in order for this
API to optimize the prompt. This function should return the
same type as the outputs in the dataset.
train_data: an evaluation dataset used for the optimization.
It should include the inputs and outputs fields with dict values.
The data must be one of the following formats:
* An EvaluationDataset entity
* Pandas DataFrame
* Spark DataFrame
* List of dictionaries
The dataset must include the following columns:
- inputs: A column containing single inputs in dict format.
Each input should contain keys matching the variables in the prompt template.
- outputs: A column containing an output for each input
that the predict_fn should produce.
If None, the optimization will be performed in zero-shot mode.
prompt_uris: a list of prompt uris to be optimized.
The prompt templates should be used by the predict_fn.
optimizer: a prompt optimizer object that optimizes a set of prompts with
the training dataset and scorers. For example,
GepaPromptOptimizer(reflection_model="openai:/gpt-4o").
scorers: List of scorers that evaluate the inputs, outputs and expectations.
Use builtin scorers like Equivalence or Correctness,
or define custom scorers with the @scorer decorator.
If None, the optimization will be performed in zero-shot mode.
`train_data` must be provided if `scorers` is provided.
aggregation: A callable that computes the overall performance metric from individual
scorer outputs. Takes a dict mapping scorer names to scores and returns a float
value (greater is better). If None and all scorers return numerical values,
uses sum of scores by default.
enable_tracking: If True (default), automatically creates an MLflow run if no active
run exists and logs the following information:
- The optimization scores (initial, final, improvement)
- Links to the optimized prompt versions
- The optimizer name and parameters
- Optimization progress
If False, no MLflow run is created and no tracking occurs.
Returns:
The optimization result object that includes the optimized prompts
as a list of prompt versions, evaluation scores, and the optimizer name.
Examples:
.. code-block:: python
import mlflow
import openai
from mlflow.genai.optimize.optimizers import GepaPromptOptimizer
from mlflow.genai.scorers import Correctness
prompt = mlflow.genai.register_prompt(
name="qa",
template="Answer the following question: {{question}}",
)
def predict_fn(question: str) -> str:
completion = openai.OpenAI().chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": prompt.format(question=question)}],
)
return completion.choices[0].message.content
dataset = [
{"inputs": {"question": "What is the capital of France?"}, "outputs": "Paris"},
{"inputs": {"question": "What is the capital of Germany?"}, "outputs": "Berlin"},
]
result = mlflow.genai.optimize_prompts(
predict_fn=predict_fn,
train_data=dataset,
prompt_uris=[prompt.uri],
optimizer=GepaPromptOptimizer(reflection_model="openai:/gpt-4o"),
scorers=[Correctness(model="openai:/gpt-4o")],
)
print(result.optimized_prompts[0].template)
**Example: Using custom scorers with an objective function**
.. code-block:: python
import mlflow
from mlflow.genai.optimize.optimizers import GepaPromptOptimizer
from mlflow.genai.scorers import scorer
# Define custom scorers
@scorer(name="accuracy")
def accuracy_scorer(outputs, expectations):
return 1.0 if outputs.lower() == expectations.lower() else 0.0
@scorer(name="brevity")
def brevity_scorer(outputs):
# Prefer shorter outputs (max 50 chars gets score of 1.0)
return min(1.0, 50 / max(len(outputs), 1))
# Define objective to combine scores
def weighted_objective(scores):
return 0.7 * scores["accuracy"] + 0.3 * scores["brevity"]
result = mlflow.genai.optimize_prompts(
predict_fn=predict_fn,
train_data=dataset,
prompt_uris=[prompt.uri],
optimizer=GepaPromptOptimizer(reflection_model="openai:/gpt-4o"),
scorers=[accuracy_scorer, brevity_scorer],
aggregation=weighted_objective,
)
refresh_mcp_server_version_tools(name: 'str', version: 'str', mcp_server_access_headers: 'Mapping[str, str] | None' = None, dry_run: 'bool' = False) -> 'MCPServerVersion'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Re-discover tools for an MCP server version and store the new snapshot.
This fetches the version's stored ``server_json``, scrapes the first usable
remote in ``server_json.remotes[]``, and updates ``tools`` on the version
with the discovered definitions. When ``dry_run=True``, the discovered tools
are only applied to the returned object and are not persisted.
Args:
name: Server name.
version: Version string.
mcp_server_access_headers: Optional HTTP headers used for the discovery
request (for example auth headers).
dry_run: If ``True``, return the version with discovered tools applied
locally without persisting the update.
Returns:
The updated :py:class:`MCPServerVersion <mlflow.entities.MCPServerVersion>`,
or a non-persisted preview when ``dry_run=True``.
register_mcp_server(server_json: 'dict[str, Any]', source: 'str | None' = None, status: "Literal['draft', 'active']" = 'draft', tools: 'list[MCPTool] | None' = <object object at 0x0000025F348EA210>, create_access_endpoints_from_remotes: 'bool' = False, mcp_server_access_headers: 'Mapping[str, str] | None' = None) -> 'MCPServerVersion'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Register an MCP server from a ``server_json`` payload.
If the parent ``MCPServer`` does not exist, it is created automatically.
If the version already exists, a ``MlflowException`` is raised.
When ``tools`` is omitted, MLflow attempts best-effort auto-discovery by
querying the first usable remote URL in ``server_json.remotes[]`` (requires
``mlflow[mcp]``), unless ``MLFLOW_ENABLE_MCP_TOOL_DISCOVERY`` is ``false``
in the current Python client process. Discovered tools are a one-time
snapshot stored on the version; they are not kept in sync with the live
server. Pass ``tools=None`` or ``tools=[]`` to disable discovery for a
single call, or pass an explicit tool list to store those definitions
instead.
Discovery failure (network, auth, protocol, timeout, or missing
``mlflow[mcp]``) does **not** abort registration: the version is created
with ``tools=None``. Discovery is bounded by a short default timeout (see
``mlflow.genai.mcp_tool_discovery.DEFAULT_MCP_TOOL_DISCOVER_TIMEOUT_SECONDS``).
Live scrape does not failover to later remotes. Auth headers for create-time
discovery are only supported here via ``mcp_server_access_headers``; REST /
``MlflowClient.create_mcp_server_version`` omit→discover has no header path
and will soft-fail to ``tools=None`` against authenticated remotes.
Access endpoints are not used for discovery (they are typically created
after the version).
Args:
server_json: The canonical MCP ``server.json`` payload. Must contain ``name``
and ``version`` at the top level.
source: Provenance URI (e.g., a git repository URL).
status: Initial status. Only ``"draft"`` and ``"active"`` are supported
during registration.
tools: Declared tool definitions for this version. Omit for best-effort
auto-discover from a deployed remote when available (failure stores
``None``). Pass ``None`` or ``[]`` to skip discovery.
create_access_endpoints_from_remotes: When ``True``, create one direct-access
endpoint per ``remotes[]`` entry in ``server_json``. This requires
``status="active"``. Independent of tool discovery.
mcp_server_access_headers: Optional HTTP headers used when auto-discovering
tools from a remote MCP server (for example auth headers). Tool lists
may vary by credentials. Ignored when discovery is not performed.
Returns:
The created :py:class:`MCPServerVersion <mlflow.entities.MCPServerVersion>`.
Example:
.. code-block:: python
import mlflow
version = mlflow.genai.register_mcp_server(
server_json={
"name": "io.github.anthropic/brave-search",
"version": "1.0.0",
"description": "Brave Search MCP server",
},
)
assert version.status == MCPStatus.DRAFT
register_mcp_server_from_url(url: 'str', source: 'str | None' = None, status: "Literal['draft', 'active']" = 'draft', tools: 'list[MCPTool] | None' = <object object at 0x0000025F348EA210>, create_access_endpoints_from_remotes: 'bool' = False, mcp_server_access_headers: 'Mapping[str, str] | None' = None) -> 'MCPServerVersion'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Fetch a ``server.json`` from a URL or local file path and register the MCP server.
When ``tools`` is omitted, MLflow attempts best-effort auto-discovery from
the first usable remote in the fetched ``server.json``. See
:func:`register_mcp_server` for discovery semantics (snapshot storage,
soft-fail on errors, and opt-out).
Args:
url: HTTP/HTTPS URL or local file path (absolute path or ``file://`` URI)
pointing to a ``server.json`` document.
source: Provenance URI; defaults to ``url`` when not provided.
status: Initial status. Only ``"draft"`` and ``"active"`` are supported
during registration.
tools: Declared tool definitions for this version. Omit for best-effort
auto-discover from a deployed remote when available. Pass ``None``
or ``[]`` to skip discovery.
create_access_endpoints_from_remotes: When ``True``, create one direct-access
endpoint per ``remotes[]`` entry in ``server_json``. This requires
``status="active"``. Independent of tool discovery.
mcp_server_access_headers: Optional HTTP headers used when auto-discovering
tools from a remote MCP server. Tool lists may vary by credentials.
Ignored when discovery is not performed.
Returns:
The created :py:class:`MCPServerVersion <mlflow.entities.MCPServerVersion>`.
register_prompt(name: str, template: str | list[dict[str, typing.Any]], commit_message: str | None = None, tags: dict[str, str] | None = None, response_format: type[pydantic.main.BaseModel] | dict[str, typing.Any] | None = None, model_config: mlflow.entities.model_registry.prompt_version.PromptModelConfig | dict[str, typing.Any] | None = None) -> mlflow.entities.model_registry.prompt_version.PromptVersion
Register a new :py:class:`Prompt <mlflow.entities.Prompt>` in the MLflow Prompt Registry.
A :py:class:`Prompt <mlflow.entities.Prompt>` is a pair of name and
template content at minimum. With MLflow Prompt Registry, you can create, manage, and
version control prompts with the MLflow's robust model tracking framework.
If there is no registered prompt with the given name, a new prompt will be created.
Otherwise, a new version of the existing prompt will be created.
Args:
name: The name of the prompt.
template: The template content of the prompt. Can be either:
- A string containing text with variables enclosed in double curly braces,
e.g. {{variable}}, which will be replaced with actual values by the `format` method.
- A list of dictionaries representing chat messages, where each message has
'role' and 'content' keys (e.g., [{"role": "user", "content": "Hello {{name}}"}])
.. note::
If you want to use the prompt with a framework that uses single curly braces
e.g. LangChain, you can use the `to_single_brace_format` method to convert the
loaded prompt to a format that uses single curly braces.
.. code-block:: python
prompt = client.load_prompt("my_prompt")
langchain_format = prompt.to_single_brace_format()
commit_message: A message describing the changes made to the prompt, similar to a
Git commit message. Optional.
tags: A dictionary of tags associated with the **prompt version**.
This is useful for storing version-specific information, such as the author of
the changes. Optional.
response_format: Optional Pydantic class or dictionary defining the expected response
structure. This can be used to specify the schema for structured outputs from LLM calls.
model_config: Optional PromptModelConfig instance or dictionary containing model-specific
configuration including model name and settings like temperature, top_p, max_tokens.
Using PromptModelConfig provides validation and type safety for common parameters.
Example (dict): {"model_name": "gpt-4", "temperature": 0.7}
Example (PromptModelConfig): PromptModelConfig(model_name="gpt-4", temperature=0.7)
Returns:
A :py:class:`Prompt <mlflow.entities.Prompt>` object that was created.
Example:
.. code-block:: python
import mlflow
# Register a text prompt
mlflow.genai.register_prompt(
name="greeting_prompt",
template="Respond to the user's message as a {{style}} AI.",
)
# Register a chat prompt with multiple messages
mlflow.genai.register_prompt(
name="assistant_prompt",
template=[
{"role": "system", "content": "You are a helpful {{style}} assistant."},
{"role": "user", "content": "{{question}}"},
],
response_format={"type": "object", "properties": {"answer": {"type": "string"}}},
)
# Load and use the prompt
prompt = mlflow.genai.load_prompt("greeting_prompt")
# Use the prompt in your application
import openai
openai_client = openai.OpenAI()
openai_client.chat.completion.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": prompt.format(style="friendly")},
{"role": "user", "content": "Hello, how are you?"},
],
)
# Update the prompt with a new version
prompt = mlflow.genai.register_prompt(
name="greeting_prompt",
template="Respond to the user's message as a {{style}} AI. {{greeting}}",
commit_message="Add a greeting to the prompt.",
tags={"author": "Bob"},
)
scorer(func: Optional[~_F] = None, *, name: str | None = None, description: str | None = None, aggregations: list[typing.Union[typing.Literal['min', 'max', 'mean', 'median', 'variance', 'p90'], typing.Callable[[list[int | float]], float]]] | None = None, pass_if: Optional[Callable[[Any], bool]] = None) -> Union[mlflow.genai.scorers.base.Scorer, Callable[[~_F], mlflow.genai.scorers.base.Scorer]]
A decorator to define a custom scorer that can be used in ``mlflow.genai.evaluate()``.
The scorer function should take in a **subset** of the following parameters:
.. list-table::
:widths: 20 20 20
:header-rows: 1
* - Parameter
- Description
- Source
* - ``inputs``
- A single input to the target model/app.
- Derived from either dataset or trace.
* When the dataset contains ``inputs`` column, the value will be passed as is.
* When traces are provided as evaluation dataset, this will be derived
from the ``inputs`` field of the trace (i.e. inputs captured as the
root span of the trace).
* - ``outputs``
- A single output from the target model/app.
- Derived from either dataset, trace, or output of ``predict_fn``.
* When the dataset contains ``outputs`` column, the value will be passed as is.
* When ``predict_fn`` is provided, MLflow will make a prediction using the
``inputs`` and the ``predict_fn`` and pass the result as the ``outputs``.
* When traces are provided as evaluation dataset, this will be derived
from the ``response`` field of the trace (i.e. outputs captured as the
root span of the trace).
* - ``expectations``
- Ground truth or any expectation for each prediction e.g., expected retrieved docs.
- Derived from either dataset or trace.
* When the dataset contains ``expectations`` column, the value will be passed as is.
* When traces are provided as evaluation dataset, this will be a dictionary
that contains a set of assessments in the format of
[assessment name]: [assessment value].
* - ``trace``
- A trace object corresponding to the prediction for the row.
- Specified as a ``trace`` column in the dataset, or generated during the prediction.
* - ``session``
- A list of trace objects belonging to the same conversation session.
- When this parameter is present, the scorer is automatically treated as a
**session-level** (multi-turn) scorer. It will be called once per session
rather than once per trace.
* ``session`` can only be combined with ``expectations``. Using ``session``
together with ``inputs``, ``outputs``, or ``trace`` is not allowed.
The scorer function should return one of the following:
* A boolean value
* An integer value
* A float value
* A string value
* A single :class:`~mlflow.entities.Feedback` object
* A list of :class:`~mlflow.entities.Feedback` objects
.. note::
The metric name will be determined by the scorer function's name or a custom name
specified in the `name` parameter for the scorer.
Args:
func: The scorer function to be decorated.
name: The name of the scorer.
description: A description of what the scorer evaluates.
aggregations: A list of aggregation functions to apply to the scorer's output.
The aggregation functions can be either a string or a callable.
* If a string, it must be one of `["min", "max", "mean", "median", "variance", "p90"]`.
* If a callable, it must take a list of values and return a single value.
By default, "mean" is used as the aggregation function.
pass_if: A predicate ``(value) -> bool`` that decides whether the scorer's
value counts as passing in ``EvaluationResult.passed``.
Use it for scorers whose value is not a ``yes``/``no`` rating or a ``bool``
(e.g. a numeric score): ``@scorer(pass_if=lambda v: v >= 0.8)``. When omitted,
the default rule applies (a ``yes`` rating or ``True`` passes).
Example:
.. code-block:: python
import json
from mlflow.genai.scorers import scorer
from mlflow.entities import AssessmentSource, Feedback
# Basic scorers that returns primitive values
@scorer
def not_empty(outputs) -> bool:
return outputs != ""
@scorer
def exact_match(outputs, expectations) -> bool:
return outputs == expectations["expected_response"]
@scorer
def num_tool_calls(trace) -> int:
spans = trace.search_spans(name="tool_call")
return len(spans)
# Use `Feedback` object to return additional information about the scorer's
# result, such as a rationale for the score.
@scorer
def harmfulness(outputs) -> Feedback:
import openai
prompt = f'''
Judge if the following text is harmful or not.
Text:
{outputs}
Return the answer in a JSON object with the following format:
{{
"harmful": true
"reason": "The text contains harmful content"
}}
Do not output any other characters than the json object.
'''
response = openai.OpenAI().chat.completions.create(
model="o4-mini",
messages=[{"role": "user", "content": prompt}],
)
payload = json.loads(response.choices[0].message.content)
return Feedback(
value=payload["harmful"],
rationale=payload["reason"],
source=AssessmentSource(
source_type="LLM_JUDGE",
source_id="openai:/o4-mini",
),
)
# Session-level scorer that evaluates an entire conversation.
# Including `session` in the function signature automatically makes this
# a session-level scorer.
@scorer
def conversation_quality(session) -> Feedback:
total_turns = len(session)
has_errors = any(t.info.status == "ERROR" for t in session)
return Feedback(
value=not has_errors, rationale=f"{total_turns} turns, errors={has_errors}"
)
# Use the scorer in an evaluation
mlflow.genai.evaluate(
data=data,
scorers=[not_empty, exact_match, num_tool_calls, harmfulness],
)
search_datasets(experiment_ids: str | list[str] | None = None, filter_string: str | None = None, max_results: int | None = None, order_by: list[str] | None = None) -> list[mlflow.genai.datasets.evaluation_dataset.EvaluationDataset]
Search for datasets.
.. warning::
Calling ``search_datasets()`` without any parameters will return ALL datasets
in your tracking server. This can be slow or even crash your Python session if
you have many datasets. Always use filters or ``max_results`` to limit the results.
Args:
experiment_ids: Single experiment ID (str) or list of experiment IDs to filter by.
If None, searches across all experiments.
filter_string: SQL-like filter string for dataset attributes. If not specified,
defaults to filtering for datasets created in the last 7 days. Supports filtering by:
- name: Dataset name
- created_by: User who created the dataset
- last_updated_by: User who last updated the dataset
- created_time: Creation timestamp (milliseconds since epoch)
- tags.<key>: Tag values
max_results: Maximum number of results. If not specified, returns all datasets.
order_by: List of columns to order by. Each entry can include an optional
"DESC" or "ASC" suffix (default is "ASC"). If not specified, defaults to
["created_time DESC"]. Supported columns:
- name
- created_time
- last_update_time
Returns:
List of EvaluationDataset objects matching the search criteria
.. list-table:: Common Search Patterns
:widths: 40 60
:header-rows: 1
* - Search Pattern
- Example Code
* - **Find datasets by name**
- .. code-block:: python
# Exact match
datasets = search_datasets(
filter_string="name = 'production_qa_v2'"
)
# Pattern matching
datasets = search_datasets(
filter_string="name LIKE 'qa_%'"
)
* - **Find datasets by experiment**
- .. code-block:: python
# Single experiment
datasets = search_datasets(
experiment_ids="1"
)
# Multiple experiments
datasets = search_datasets(
experiment_ids=["0", "1", "2", "5"]
)
* - **Find datasets by tags**
- .. code-block:: python
# Single tag
datasets = search_datasets(
filter_string="tags.environment = 'production'"
)
# Multiple tags with AND
datasets = search_datasets(
filter_string="tags.status = 'validated' AND tags.version = '2.0'"
)
* - **Find datasets by creator**
- .. code-block:: python
datasets = search_datasets(
filter_string="created_by = 'alice@company.com'"
)
* - **Find recent datasets**
- .. code-block:: python
# Last 10 datasets created
datasets = search_datasets(
order_by=["created_time DESC"],
max_results=10
)
* - **Complex search**
- .. code-block:: python
# Production-ready datasets from specific team
datasets = search_datasets(
experiment_ids="1",
filter_string="tags.status = 'production' AND "
"tags.team = 'ml-platform' AND "
"name LIKE '%customer%'",
order_by=["last_update_time DESC"],
max_results=20
)
Examples:
.. code-block:: python
from mlflow.genai.datasets import search_datasets
# WARNING: This returns ALL datasets - use with caution!
# all_datasets = search_datasets() # May be slow or crash
# Better: Always use filters or limits
recent_datasets = search_datasets(max_results=100)
# Search in specific experiments
exp_datasets = search_datasets(experiment_ids=["1", "2", "3"])
# Find production datasets
prod_datasets = search_datasets(
filter_string="tags.environment = 'production'", order_by=["name ASC"]
)
# Iterate through results (pagination handled automatically)
for dataset in prod_datasets:
print(f"{dataset.name} (ID: {dataset.dataset_id})")
print(f" Tags: {dataset.tags}")
search_mcp_access_endpoints(server_name: 'str | None' = None, server_version: 'str | None' = None, server_alias: 'str | None' = None, filter_string: 'str | None' = None, max_results: 'int' = 1000, order_by: 'list[str] | None' = None, page_token: 'str | None' = None) -> 'PagedList[MCPAccessEndpoint]'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Search access endpoints across the workspace.
Args:
server_name: If provided, limit results to this server.
server_version: If provided, limit results to endpoints targeting this version.
server_alias: If provided, limit results to endpoints targeting this alias.
filter_string: SQL-like filter. See
``https://mlflow.org/docs/latest/ml/search/search-runs/#search-query-syntax-deep-dive``
for the filter syntax guide.
max_results: Maximum number of results.
order_by: List of columns to order by.
page_token: Token for the next page.
Returns:
A :py:class:`PagedList <mlflow.store.entities.PagedList>` of
:py:class:`MCPAccessEndpoint <mlflow.entities.MCPAccessEndpoint>` objects.
search_mcp_server_versions(name: 'str', filter_string: 'str | None' = None, max_results: 'int' = 1000, order_by: 'list[str] | None' = None, page_token: 'str | None' = None) -> 'PagedList[MCPServerVersion]'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Search versions of a specific MCP server.
Args:
name: Server name.
filter_string: SQL-like filter (e.g., ``"status = 'active'"``). See
``https://mlflow.org/docs/latest/ml/search/search-runs/#search-query-syntax-deep-dive``
for the filter syntax guide.
max_results: Maximum number of results.
order_by: List of columns to order by.
page_token: Token for the next page.
Returns:
A :py:class:`PagedList <mlflow.store.entities.PagedList>` of
:py:class:`MCPServerVersion <mlflow.entities.MCPServerVersion>` objects.
search_mcp_servers(filter_string: 'str | None' = None, max_results: 'int' = 1000, order_by: 'list[str] | None' = None, page_token: 'str | None' = None) -> 'PagedList[MCPServer]'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Search MCP servers with optional filtering and pagination.
Args:
filter_string: SQL-like filter expression (e.g., ``"status = 'active'"``,
``"tags.team = 'platform'"``, ``"has_access_endpoints = 'true'"``).
See
``https://mlflow.org/docs/latest/ml/search/search-runs/#search-query-syntax-deep-dive``
for the filter syntax guide.
max_results: Maximum number of results to return.
order_by: List of columns to order by.
page_token: Token for retrieving the next page of results.
Returns:
A :py:class:`PagedList <mlflow.store.entities.PagedList>` of
:py:class:`MCPServer <mlflow.entities.MCPServer>` objects.
Example:
.. code-block:: python
import mlflow
servers = mlflow.genai.search_mcp_servers(filter_string="status = 'active'")
for server in servers:
print(server.name, server.status)
search_prompts(filter_string: str | None = None, max_results: int | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.model_registry.prompt.Prompt]
set_dataset_tags(dataset_id: str, tags: dict[str, typing.Any]) -> None
Set tags for a dataset.
This implements a batch tag operation - existing tags are merged with new tags.
To remove a tag, set its value to None or use delete_dataset_tag() instead.
Args:
dataset_id: The ID of the dataset.
tags: Dictionary of tags to set. Setting a value to None removes the tag.
Examples:
.. code-block:: python
from mlflow.genai.datasets import set_dataset_tags, get_dataset
# Get your dataset
dataset = get_dataset(dataset_id="d-8f3a2b1c4e5d6f7a8b9c0d1e2f3a4b5c")
# Add or update multiple tags
set_dataset_tags(
dataset_id=dataset.dataset_id,
tags={
"environment": "production", # Add new tag
"version": "2.0", # Update existing tag
"validated": "true",
"validation_date": "2024-11-01",
"team": "ml-platform",
},
)
# Remove tags by setting to None
set_dataset_tags(
dataset_id=dataset.dataset_id,
tags={
"deprecated_tag": None, # This removes the tag
"old_version": None, # This also removes the tag
},
)
# Update status after validation
set_dataset_tags(
dataset_id=dataset.dataset_id,
tags={
"status": "production_ready",
"coverage": "comprehensive",
"last_review": "2024-11-01",
"approved_by": "data_science_lead@company.com",
},
)
Note:
This API is not available in Databricks environments yet.
Tags in Databricks are managed through Unity Catalog.
set_mcp_server_alias(name: 'str', alias: 'str', version: 'str') -> 'None'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Set an alias on an MCP server pointing to a specific version (upsert).
The alias name ``"latest"`` is reserved and cannot be set here.
Args:
name: Server name.
alias: Alias name (e.g., ``"production"``).
version: Target version string.
set_mcp_server_tag(name: 'str', key: 'str', value: 'str') -> 'None'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Set a tag on an MCP server (upsert).
Tags are the API term for these user-defined metadata entries. Some UI
surfaces may label the same concept as metadata.
Args:
name: Server name.
key: Tag key.
value: Tag value.
set_mcp_server_version_tag(name: 'str', version: 'str', key: 'str', value: 'str') -> 'None'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Set a tag on an MCP server version (upsert).
Tags are the API term for these user-defined metadata entries. Some UI
surfaces may label the same concept as metadata.
Args:
name: Server name.
version: Version string.
key: Tag key.
value: Tag value.
set_prompt_alias(name: str, alias: str, version: int) -> None
Set an alias for a :py:class:`Prompt <mlflow.entities.Prompt>` in the MLflow Prompt Registry.
Args:
name: The name of the prompt.
alias: The alias to set for the prompt.
version: The version of the prompt.
Example:
.. code-block:: python
import mlflow
# Set an alias for the prompt
mlflow.genai.set_prompt_alias(name="my_prompt", version=1, alias="production")
# Load the prompt by alias (use "@" to specify the alias)
prompt = mlflow.genai.load_prompt("prompts:/my_prompt@production")
# Switch the alias to a new version of the prompt
mlflow.genai.set_prompt_alias(name="my_prompt", version=2, alias="production")
# Delete the alias
mlflow.genai.delete_prompt_alias(name="my_prompt", alias="production")
set_prompt_model_config(name: str, version: str | int, model_config: mlflow.entities.model_registry.prompt_version.PromptModelConfig | dict[str, typing.Any]) -> None
Set or update the model configuration for a specific prompt version.
Model configuration includes model-specific settings such as model name, temperature,
max_tokens, and other inference parameters. Unlike the prompt template, model configuration
is mutable and can be updated after a prompt version is created.
Args:
name: The name of the prompt.
version: The version of the prompt.
model_config: A PromptModelConfig or dict with model settings like model_name, temperature.
Example:
.. code-block:: python
import mlflow
from mlflow.entities.model_registry import PromptModelConfig
# Set model config using a dictionary
mlflow.genai.set_prompt_model_config(
name="my-prompt",
version=1,
model_config={"model_name": "gpt-4", "temperature": 0.7, "max_tokens": 1000},
)
# Set model config using PromptModelConfig for validation
config = PromptModelConfig(
model_name="gpt-4-turbo",
temperature=0.5,
max_tokens=2000,
top_p=0.95,
)
mlflow.genai.set_prompt_model_config(
name="my-prompt",
version=1,
model_config=config,
)
# Load and verify the config was set
prompt = mlflow.genai.load_prompt("my-prompt", version=1)
print(prompt.model_config)
set_prompt_tag(name: str, key: str, value: str) -> None
Set a tag on a prompt in the MLflow Prompt Registry.
Args:
name: The name of the prompt.
key: The key of the tag
value: The value of the tag for the key
set_prompt_version_tag(name: str, version: str | int, key: str, value: str) -> None
Set a tag on a prompt version in the MLflow Prompt Registry.
Args:
name: The name of the prompt.
version: The version of the prompt.
key: The key of the tag
value: The value of the tag for the key
test_agent(predict_fn: 'Callable[..., Any]', *, experiment_id: 'str | None' = None, traces: 'list[Trace] | None' = None, model: 'str | None' = None, max_turns: 'int' = 10, max_issues: 'int' = 20, num_test_cases: 'int | None' = None, guidance: 'str | None' = None) -> 'AgentTestResult'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Automatically stress-test a conversational AI agent and discover issues.
Runs a multi-step pipeline:
1. **Describe** — asks the agent to describe itself (falls back to
analysing existing traces when available).
2. **Generate test cases** — uses an LLM to create diverse,
targeted test scenarios from the agent description.
3. **Simulate conversations** — runs each test case through the
:class:`~mlflow.genai.simulators.ConversationSimulator`.
4. **Detect issues** — analyses simulation traces with
``discover_issues``.
Args:
predict_fn: Agent function compatible with
:class:`~mlflow.genai.simulators.ConversationSimulator`.
Must accept either ``input`` or ``messages`` for conversation
history.
experiment_id: Optional experiment containing existing traces to
help describe the agent. Ignored when ``traces`` is provided.
traces: Optional list of existing traces to help describe the
agent.
model: LLM used for analysis, test generation, and simulation.
Defaults to the configured default simulation model when ``None``.
max_turns: Maximum conversation turns per test case.
max_issues: Maximum number of issues to report.
num_test_cases: Number of test cases to generate. Defaults to
``7`` when ``None``.
guidance: Optional natural-language guidance for what kinds of
queries to test. For example,
``"Focus on multi-step financial workflows"``.
When ``None``, uses a default that covers a broad,
realistic mix of the agent's capabilities.
Returns:
An :class:`AgentTestResult` containing discovered issues, generated
test cases, the agent description, simulation traces, and the
full :class:`~mlflow.genai.discovery.entities.DiscoverIssuesResult`.
Example:
.. code-block:: python
from openai import OpenAI
import mlflow
client = OpenAI()
@mlflow.trace
def agent(input: list[dict], **kwargs) -> dict:
mlflow.update_current_trace(session_id=kwargs.get("mlflow_session_id"))
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "system", "content": "You are a helpful assistant."}] + input,
)
content = response.choices[0].message.content
return {"choices": [{"message": {"role": "assistant", "content": content}}]}
result = mlflow.genai.test_agent(agent, model="openai:/gpt-4o-mini")
print(result)
to_predict_fn(endpoint_uri: str) -> Callable[..., Any]
Convert an endpoint URI to a predict function.
Args:
endpoint_uri: The endpoint URI to convert. Supports:
- "endpoints:/<endpoint-name>" for Databricks model serving endpoints
- "apps:/<app-name>" for Databricks Apps
Returns:
A predict function that can be used to make predictions.
Example for model serving endpoints:
The following example assumes that the model serving endpoint accepts a JSON
object with a `messages` key. Please adjust the input based on the actual
schema of the model serving endpoint.
.. code-block:: python
from mlflow.genai.scorers import get_all_scorers
data = [
{
"inputs": {
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is MLflow?"},
]
}
},
{
"inputs": {
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is Spark?"},
]
}
},
]
predict_fn = mlflow.genai.to_predict_fn("endpoints:/chat")
mlflow.genai.evaluate(
data=data,
predict_fn=predict_fn,
scorers=get_all_scorers(),
)
You can also directly invoke the function to validate if the endpoint works
properly with your input schema.
.. code-block:: python
predict_fn(**data[0]["inputs"])
Example for Databricks Apps:
.. code-block:: python
from mlflow.genai.scorers import RelevanceToQuery, Safety
data = [
{
"inputs": {"input": [{"role": "user", "content": "Calculate 15th Fibonacci"}]},
}
]
predict_fn = mlflow.genai.to_predict_fn("apps:/agent-app")
mlflow.genai.evaluate(
data=data,
predict_fn=predict_fn,
scorers=[RelevanceToQuery(), Safety()],
)
update_mcp_access_endpoint(server_name: 'str', endpoint_id: 'str', url: 'str | None' = <object object at 0x0000025F348EA210>, transport_type: "Literal['streamable-http', 'sse'] | None" = <object object at 0x0000025F348EA210>, server_version: 'str | None' = <object object at 0x0000025F348EA210>, server_alias: 'str | None' = <object object at 0x0000025F348EA210>) -> 'MCPAccessEndpoint'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Update an existing access endpoint.
Only fields that are explicitly passed are updated; omitted fields are left
unchanged. Pass ``None`` to clear a field.
Args:
server_name: Server name.
endpoint_id: Endpoint ID.
url: New endpoint URL. Pass ``None`` to clear.
transport_type: New transport type. Pass ``None`` to clear.
server_version: New version target. Pass ``None`` to clear.
server_alias: New alias target. Pass ``None`` to clear.
Returns:
The updated :py:class:`MCPAccessEndpoint <mlflow.entities.MCPAccessEndpoint>`.
update_mcp_server(name: 'str', display_name: 'str | None' = <object object at 0x0000025F348EA210>, description: 'str | None' = <object object at 0x0000025F348EA210>, icons: 'list[MCPIcon] | None' = <object object at 0x0000025F348EA210>) -> 'MCPServer'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Update mutable fields of an MCP server.
Only fields that are explicitly passed are updated; omitted fields are left
unchanged. Pass ``None`` to clear a field.
Args:
name: Server name.
display_name: New human-readable label. Pass ``None`` to clear.
description: New description. Pass ``None`` to clear.
icons: New icon variants. Pass ``None`` to clear.
Returns:
The updated :py:class:`MCPServer <mlflow.entities.MCPServer>`.
update_mcp_server_version(name: 'str', version: 'str', status: "Literal['draft', 'active', 'deprecated', 'deleted'] | None" = <object object at 0x0000025F348EA210>, tools: 'list[MCPTool] | None' = <object object at 0x0000025F348EA210>, connect_options: 'dict[str, ConnectOptionSettings] | None' = <object object at 0x0000025F348EA210>) -> 'MCPServerVersion'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Update mutable fields of an MCP server version.
Only fields that are explicitly passed are updated; omitted fields are left
unchanged. Pass ``None`` to clear a field.
Args:
name: Server name.
version: Version string.
status: New status (``"draft"``, ``"active"``, ``"deprecated"``,
``"deleted"``). Transition rules are enforced.
tools: New tool definitions. Pass ``None`` to clear. Does not
auto-discover tools from remotes; pass an explicit list (or clear).
connect_options: Per-key settings for connect options (e.g. visibility).
Pass ``None`` to clear.
Returns:
The updated :py:class:`MCPServerVersion <mlflow.entities.MCPServerVersion>`.
DATA
__all__ = ['datasets', 'test_agent', 'evaluate', 'to_predict_fn', 'Sco...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\genai\__init__.py
mlflow.get_active_model_id
Python Library Documentation: function get_active_model_id in module mlflow.tracking.fluent
get_active_model_id() -> str | None
Get the active model ID. If no active model is set with ``set_active_model()``, the
default active model is set using model ID from the environment variable
``MLFLOW_ACTIVE_MODEL_ID`` or the legacy environment variable ``_MLFLOW_ACTIVE_MODEL_ID``.
If neither is set, return None. Note that this function only get the active model ID from the
current thread.
Returns:
The active model ID if set, otherwise None.
mlflow.get_active_trace_id
Python Library Documentation: function get_active_trace_id in module mlflow.tracing.fluent
get_active_trace_id() -> 'str | None'
Get the active trace ID in the current process.
This function is thread-safe.
Example:
.. code-block:: python
:test:
import mlflow
@mlflow.trace
def f():
trace_id = mlflow.get_active_trace_id()
print(trace_id)
f()
Returns:
The ID of the current active trace if exists, otherwise None.
mlflow.get_artifact_uri
Python Library Documentation: function get_artifact_uri in module mlflow.tracking.fluent
get_artifact_uri(artifact_path: str | None = None) -> str
Get the absolute URI of the specified artifact in the currently active run.
If `path` is not specified, the artifact root URI of the currently active
run will be returned; calls to ``log_artifact`` and ``log_artifacts`` write
artifact(s) to subdirectories of the artifact root URI.
If no run is active, this method will create a new active run.
Args:
artifact_path: The run-relative artifact path for which to obtain an absolute URI.
For example, "path/to/artifact". If unspecified, the artifact root URI
for the currently active run will be returned.
Returns:
An *absolute* URI referring to the specified artifact or the currently active run's
artifact root. For example, if an artifact path is provided and the currently active
run uses an S3-backed store, this may be a uri of the form
``s3://<bucket_name>/path/to/artifact/root/path/to/artifact``. If an artifact path
is not provided and the currently active run uses an S3-backed store, this may be a
URI of the form ``s3://<bucket_name>/path/to/artifact/root``.
.. code-block:: python
:test:
:caption: Example
import tempfile
import mlflow
features = "rooms, zipcode, median_price, school_rating, transport"
with tempfile.NamedTemporaryFile("w") as tmp_file:
tmp_file.write(features)
tmp_file.flush()
# Log the artifact in a directory "features" under the root artifact_uri/features
with mlflow.start_run():
mlflow.log_artifact(tmp_file.name, artifact_path="features")
# Fetch the artifact uri root directory
artifact_uri = mlflow.get_artifact_uri()
print(f"Artifact uri: {artifact_uri}")
# Fetch a specific artifact uri
artifact_uri = mlflow.get_artifact_uri(artifact_path="features/features.txt")
print(f"Artifact uri: {artifact_uri}")
.. code-block:: text
:caption: Output
Artifact uri: file:///.../0/a46a80f1c9644bd8f4e5dd5553fffce/artifacts
Artifact uri: file:///.../0/a46a80f1c9644bd8f4e5dd5553fffce/artifacts/features/features.txt
mlflow.get_assessment
Python Library Documentation: function get_assessment in module mlflow.tracing.assessment
get_assessment(trace_id: str, assessment_id: str) -> mlflow.entities.assessment.Assessment
Get an assessment entity from the backend store.
Args:
trace_id: The ID of the trace.
assessment_id: The ID of the assessment to get.
Returns:
:py:class:`~mlflow.entities.Assessment`: The Assessment object.
mlflow.get_current_active_span
Python Library Documentation: function get_current_active_span in module mlflow.tracing.fluent
get_current_active_span() -> 'LiveSpan | None'
Get the current active span in the global context.
.. attention::
This only works when the span is created with fluent APIs like `@mlflow.trace` or
`with mlflow.start_span`. If a span is created with the
`mlflow.start_span_no_context` APIs, it won't be
attached to the global context so this function will not return it.
.. code-block:: python
:test:
import mlflow
@mlflow.trace
def f():
span = mlflow.get_current_active_span()
span.set_attribute("key", "value")
return 0
f()
Returns:
The current active span if exists, otherwise None.
mlflow.get_experiment
Python Library Documentation: function get_experiment in module mlflow.tracking.fluent
get_experiment(experiment_id: str) -> mlflow.entities.experiment.Experiment
Retrieve an experiment by experiment_id from the backend store
Args:
experiment_id: The string-ified experiment ID returned from ``create_experiment``.
Returns:
:py:class:`mlflow.entities.Experiment`
.. code-block:: python
:test:
:caption: Example
import mlflow
experiment = mlflow.get_experiment("0")
print(f"Name: {experiment.name}")
print(f"Artifact Location: {experiment.artifact_location}")
print(f"Tags: {experiment.tags}")
print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
print(f"Creation timestamp: {experiment.creation_time}")
.. code-block:: text
:caption: Output
Name: Default
Artifact Location: file:///.../mlruns/0
Tags: {}
Lifecycle_stage: active
Creation timestamp: 1662004217511
mlflow.get_experiment_by_name
Python Library Documentation: function get_experiment_by_name in module mlflow.tracking.fluent
get_experiment_by_name(name: str) -> mlflow.entities.experiment.Experiment | None
Retrieve an experiment by experiment name from the backend store
Args:
name: The case sensitive experiment name.
Returns:
An instance of :py:class:`mlflow.entities.Experiment`
if an experiment with the specified name exists, otherwise None.
.. code-block:: python
:test:
:caption: Example
import mlflow
# Case sensitive name
experiment = mlflow.get_experiment_by_name("Default")
print(f"Experiment_id: {experiment.experiment_id}")
print(f"Artifact Location: {experiment.artifact_location}")
print(f"Tags: {experiment.tags}")
print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
print(f"Creation timestamp: {experiment.creation_time}")
.. code-block:: text
:caption: Output
Experiment_id: 0
Artifact Location: file:///.../mlruns/0
Tags: {}
Lifecycle_stage: active
Creation timestamp: 1662004217511
mlflow.get_last_active_trace_id
Python Library Documentation: function get_last_active_trace_id in module mlflow.tracing.fluent
get_last_active_trace_id(thread_local: 'bool' = False) -> 'str | None'
Get the **LAST** active trace in the same process if exists.
.. warning::
This function is not thread-safe by default, returns the last active trace in
the same process. If you want to get the last active trace in the current thread,
set the `thread_local` parameter to True.
Args:
thread_local: If True, returns the last active trace in the current thread. Otherwise,
returns the last active trace in the same process. Default is False.
Returns:
The ID of the last active trace if exists, otherwise None.
.. code-block:: python
:test:
import mlflow
@mlflow.trace
def f():
pass
f()
trace_id = mlflow.get_last_active_trace_id()
# Set a tag on the trace
mlflow.set_trace_tag(trace_id, "key", "value")
# Get the full trace object
trace = mlflow.get_trace(trace_id)
mlflow.get_logged_model
Python Library Documentation: function get_logged_model in module mlflow.tracking.fluent
get_logged_model(model_id: str) -> mlflow.entities.logged_model.LoggedModel
Get a logged model by ID.
Args:
model_id: The ID of the logged model.
Returns:
The logged model.
Example:
.. code-block:: python
:test:
import mlflow
class DummyModel(mlflow.pyfunc.PythonModel):
def predict(self, context, model_input: list[str]) -> list[str]:
return model_input
model_info = mlflow.pyfunc.log_model(name="model", python_model=DummyModel())
logged_model = mlflow.get_logged_model(model_id=model_info.model_id)
assert logged_model.model_id == model_info.model_id
mlflow.get_parent_run
Python Library Documentation: function get_parent_run in module mlflow.tracking.fluent
get_parent_run(run_id: str) -> mlflow.entities.run.Run | None
Gets the parent run for the given run id if one exists.
Args:
run_id: Unique identifier for the child run.
Returns:
A single :py:class:`mlflow.entities.Run` object, if the parent run exists. Otherwise,
returns None.
.. code-block:: python
:test:
:caption: Example
import mlflow
# Create nested runs
with mlflow.start_run():
with mlflow.start_run(nested=True) as child_run:
child_run_id = child_run.info.run_id
parent_run = mlflow.get_parent_run(child_run_id)
print(f"child_run_id: {child_run_id}")
print(f"parent_run_id: {parent_run.info.run_id}")
.. code-block:: text
:caption: Output
child_run_id: 7d175204675e40328e46d9a6a5a7ee6a
parent_run_id: 8979459433a24a52ab3be87a229a9cdf
mlflow.get_registry_uri
Python Library Documentation: function get_registry_uri in module mlflow.tracking._model_registry.utils
get_registry_uri() -> str
Get the current registry URI. If none has been specified, defaults to the tracking URI.
Returns:
The registry URI.
.. code-block:: python
# Get the current model registry uri
mr_uri = mlflow.get_registry_uri()
print(f"Current model registry uri: {mr_uri}")
# Get the current tracking uri
tracking_uri = mlflow.get_tracking_uri()
print(f"Current tracking uri: {tracking_uri}")
# They should be the same
assert mr_uri == tracking_uri
.. code-block:: text
Current model registry uri: file:///.../mlruns
Current tracking uri: file:///.../mlruns
mlflow.get_run
Python Library Documentation: function get_run in module mlflow.tracking.fluent
get_run(run_id: str) -> mlflow.entities.run.Run
Fetch the run from backend store. The resulting Run contains a collection of run metadata --
RunInfo as well as a collection of run parameters, tags, and metrics -- RunData. It also
contains a collection of run inputs (experimental), including information about datasets used by
the run -- RunInputs. In the case where multiple metrics with the same key are logged for the
run, the RunData contains the most recently logged value at the largest step for each metric.
Args:
run_id: Unique identifier for the run.
Returns:
A single Run object, if the run exists. Otherwise, raises an exception.
.. code-block:: python
:test:
:caption: Example
import mlflow
with mlflow.start_run() as run:
mlflow.log_param("p", 0)
run_id = run.info.run_id
print(f"run_id: {run_id}; lifecycle_stage: {mlflow.get_run(run_id).info.lifecycle_stage}")
.. code-block:: text
:caption: Output
run_id: 7472befefc754e388e8e922824a0cca5; lifecycle_stage: active
mlflow.get_trace
Python Library Documentation: function get_trace in module mlflow.tracing.fluent
get_trace(trace_id: 'str', silent: 'bool' = False, flush: 'bool' = False) -> 'Trace | None'
.. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
Get a trace by the given request ID if it exists.
This function retrieves the trace from the in-memory buffer first, and if it doesn't exist,
it fetches the trace from the tracking store. If the trace is not found in the tracking store,
it returns None.
Args:
trace_id: The ID of the trace.
silent: If True, suppress the warning message when the trace is not found. The API will
return None without any warning. Default to False.
flush: If True and the trace is not found, flush any pending async trace writes and
retry. Useful in tests or scripts where async logging may not have completed.
Default to False.
.. code-block:: python
:test:
import mlflow
with mlflow.start_span(name="span") as span:
span.set_attribute("key", "value")
trace = mlflow.get_trace(span.trace_id)
print(trace)
Returns:
A :py:class:`mlflow.entities.Trace` objects with the given request ID.
mlflow.get_tracking_uri
Python Library Documentation: function get_tracking_uri in module mlflow.tracking._tracking_service.utils
get_tracking_uri() -> str
Get the current tracking URI. This may not correspond to the tracking URI of
the currently active run, since the tracking URI can be updated via ``set_tracking_uri``.
Returns:
The tracking URI.
.. code-block:: python
import mlflow
# Get the current tracking uri
tracking_uri = mlflow.get_tracking_uri()
print(f"Current tracking uri: {tracking_uri}")
.. code-block:: text
Current tracking uri: sqlite:///mlflow.db
mlflow.get_workspace
Python Library Documentation: function get_workspace in module mlflow.tracking._workspace.fluent
get_workspace(name: 'str') -> 'Workspace'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Return metadata for the specified workspace.
mlflow.groq
Python Library Documentation: package mlflow.groq in mlflow
NAME
mlflow.groq - The ``mlflow.groq`` module provides an API for logging and loading Groq models.
PACKAGE CONTENTS
_groq_autolog
DATA
FLAVOR_NAME = 'groq'
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\groq\__init__.py
mlflow.h2o
Python Library Documentation: package mlflow.h2o in mlflow
NAME
mlflow.h2o
DESCRIPTION
The ``mlflow.h2o`` module provides an API for logging and loading H2O models. This module exports
H2O models with the following flavors:
H20 (native) format
This is the main flavor that can be loaded back into H2O.
:py:mod:`mlflow.pyfunc`
Produced for use by generic pyfunc-based deployment tools and batch inference.
PACKAGE CONTENTS
DATA
FLAVOR_NAME = 'h2o'
LOG_MODEL_PARAM_DOCS = ParamDocs({'name': 'Model name.', 'conda_env': ...
MLMODEL_FILE_NAME = 'MLmodel'
ModelInputExample = typing.Union[pandas.core.frame.DataFrame, numpy......
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\h2o\__init__.py
mlflow.haystack
Error rendering doc: No module named 'haystack'
mlflow.import_checkpoints
Python Library Documentation: function import_checkpoints in module mlflow.tracking.fluent
import_checkpoints(checkpoint_path: str, source_run_id: str | None = None, model_prefix: str | None = None, overwrite_checkpoints: bool = False) -> list[mlflow.entities.logged_model.LoggedModel]
Create external models for all top-level files and directories under the specified
checkpoint path.
This API only supports Databricks runtime currently.
Args:
checkpoint_path: Path that contains the checkpoints.
Only Databricks Unity Catalog Volume path is supported for now.
It must follows the
"/Volumes/<catalog_identifier>/<schema_identifier>/<volume_identifier>/<path_to_checkpoints_directory>"
format specified https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-volumes#volume-naming-and-reference.
Note: Each path must be isolated from other models and runs.
source_run_id: ID of the MLflow source run that these checkpoints were trained with.
If not provided, uses the current active run if available.
model_prefix: String prefix to prepend to the name of each external model created from
each checkpoint. If not provided, no prefix is applied.
overwrite_checkpoints: If True and existing models are found with the same name in the
associated experiment, they will be deleted and recreated to point to the latest
checkpoint. Defaults to False.
Returns:
List of imported models. If 'overwrite_checkpoints' is True, the list only contains
new created models, otherwise the list contains new created models for the new model
names and existing models for the existing model names.
Example:
.. code-block:: python
import mlflow
# Optionally start a run so `source_run_id` can be inferred
with mlflow.start_run() as run:
# ... training code that writes checkpoints to a UC Volume ...
logged_models = mlflow.import_checkpoints(
checkpoint_path=(
"/Volumes/mycatalog/myschema/myvolume/mytrainingmodel/trainingrun1/checkpoints"
),
# You can omit `source_run_id` if there is an active run.
# source_run_id=run.info.run_id,
model_prefix="my_model_",
overwrite_checkpoints=True,
)
mlflow.initialize_logged_model
Python Library Documentation: function initialize_logged_model in module mlflow.tracking.fluent
initialize_logged_model(name: str | None = None, source_run_id: str | None = None, tags: dict[str, str] | None = None, params: dict[str, str] | None = None, model_type: str | None = None, experiment_id: str | None = None) -> mlflow.entities.logged_model.LoggedModel
Initialize a LoggedModel. Creates a LoggedModel with status ``PENDING`` and no artifacts. You
must add artifacts to the model and finalize it to the ``READY`` state, for example by calling
a flavor-specific ``log_model()`` method such as :py:func:`mlflow.pyfunc.log_model()`.
Args:
name: The name of the model. If not specified, a random name will be generated.
source_run_id: The ID of the run that the model is associated with. If unspecified and a
run is active, the active run ID will be used.
tags: A dictionary of string keys and values to set as tags on the model.
params: A dictionary of string keys and values to set as parameters on the model.
model_type: The type of the model.
experiment_id: The experiment ID of the experiment to which the model belongs.
Returns:
A new :py:class:`mlflow.entities.LoggedModel` object with status ``PENDING``.
mlflow.is_tracking_uri_set
Python Library Documentation: function is_tracking_uri_set in module mlflow.tracking._tracking_service.utils
is_tracking_uri_set()
Returns True if the tracking URI has been set, False otherwise.
mlflow.johnsnowlabs
Python Library Documentation: package mlflow.johnsnowlabs in mlflow
NAME
mlflow.johnsnowlabs
DESCRIPTION
The ``mlflow.johnsnowlabs`` module provides an API for logging and loading Spark NLP and NLU models.
This module exports the following flavors:
Johnsnowlabs (native) format
Allows models to be loaded as Spark Transformers for scoring in a Spark session.
Models with this flavor can be loaded as NluPipelines, with underlying Spark MLlib PipelineModel
This is the main flavor and is always produced.
:py:mod:`mlflow.pyfunc`
Supports deployment outside of Spark by instantiating a SparkContext and reading
input data as a Spark DataFrame prior to scoring. Also supports deployment in Spark
as a Spark UDF. Models with this flavor can be loaded as Python functions
for performing inference. This flavor is always produced.
This flavor gives you access to `20.000+ state-of-the-art enterprise NLP models in 200+ languages
<https://nlp.johnsnowlabs.com/models>`_ for medical, finance, legal and many more domains.
Features include: LLM's, Text Summarization, Question Answering, Named Entity Recognition, Relation
Extraction, Sentiment Analysis, Spell Checking, Image Classification, Automatic Speech Recognition
and much more, powered by the latest Transformer Architectures. The models are provided by
`John Snow Labs <https://www.johnsnowlabs.com/>`_ and requires a `John Snow Labs
<https://www.johnsnowlabs.com/>`_ Enterprise NLP License. `You can reach out to us
<https://www.johnsnowlabs.com/schedule-a-demo/>`_ for a research or industry license.
These keys must be present in your license json:
1. ``SECRET``: The secret for the John Snow Labs Enterprise NLP Library
2. ``SPARK_NLP_LICENSE``: Your John Snow Labs Enterprise NLP License
3. ``AWS_ACCESS_KEY_ID``: Your AWS Secret ID for accessing John Snow Labs Enterprise Models
4. ``AWS_SECRET_ACCESS_KEY``: Your AWS Secret key for accessing John Snow Labs Enterprise Models
You can set them using the following code:
.. code-block:: python
import os
import json
# Write your raw license.json string into the 'JOHNSNOWLABS_LICENSE_JSON' env variable
creds = {
"AWS_ACCESS_KEY_ID": "...",
"AWS_SECRET_ACCESS_KEY": "...",
"SPARK_NLP_LICENSE": "...",
"SECRET": "...",
}
os.environ["JOHNSNOWLABS_LICENSE_JSON"] = json.dumps(creds)
PACKAGE CONTENTS
DATA
DEFAULT_AWAIT_MAX_SLEEP_SECONDS = 300
FLAVOR_NAME = 'johnsnowlabs'
LOG_MODEL_PARAM_DOCS = ParamDocs({'name': 'Model name.', 'conda_env': ...
MLFLOW_DFS_TMP = 'MLFLOW_DFS_TMP'
MLMODEL_FILE_NAME = 'MLmodel'
ModelInputExample = typing.Union[pandas.core.frame.DataFrame, numpy......
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\johnsnowlabs\__init__.py
mlflow.keras
Error rendering doc: initialization of _pywrap_checkpoint_reader raised unreported exception
mlflow.langchain
Python Library Documentation: package mlflow.langchain in mlflow
NAME
mlflow.langchain
PACKAGE CONTENTS
_compat
api_request_parallel_processor
autolog
chat_agent_langgraph
constant
constants
databricks_dependencies
langchain_tracer
model
output_parsers
retriever_chain
runnables
utils (package)
CLASSES
builtins.object
mlflow.langchain.model._LangChainModelWrapper
class _LangChainModelWrapper(builtins.object)
| _LangChainModelWrapper(lc_model, model_path=None)
|
| Methods defined here:
|
| __init__(self, lc_model, model_path=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| get_raw_model(self)
| Returns the underlying model.
|
| predict(self, data: pandas.core.frame.DataFrame | list[str | dict[str, typing.Any]] | typing.Any, params: dict[str, typing.Any] | None = None) -> list[str | dict[str, typing.Any]]
| Args:
| data: Model input data.
| params: Additional parameters to pass to the model for inference.
|
| Returns:
| Model predictions.
|
| predict_stream(self, data: Any, params: dict[str, typing.Any] | None = None) -> Iterator[dict[str, Any] | str]
| Args:
| data: Model input data, only single input is allowed.
| params: Additional parameters to pass to the model for inference.
|
| Returns:
| An iterator of model prediction chunks.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FUNCTIONS
_load_pyfunc(path: str, model_config: dict[str, typing.Any] | None = None)
Load PyFunc implementation for LangChain. Called by ``pyfunc.load_model``.
Args:
path: Local filesystem path to the MLflow Model with the ``langchain`` flavor.
autolog(disable=False, exclusive=False, disable_for_unsupported_versions=False, silent=False, log_traces=True, run_tracer_inline=False)
.. Note:: Autologging is known to be compatible with the following package versions: ``1.0.0`` <= ``langchain`` <= ``1.3.14``. Autologging may not succeed when used with package versions outside of this range.
Enables (or disables) and configures autologging from Langchain to MLflow.
Args:
disable: If ``True``, disables the Langchain autologging integration. If ``False``,
enables the Langchain autologging integration.
exclusive: If ``True``, autologged content is not logged to user-created fluent runs.
If ``False``, autologged content is logged to the active fluent run,
which may be user-created.
disable_for_unsupported_versions: If ``True``, disable autologging for versions of
langchain that have not been tested against this version of the MLflow
client or are incompatible.
silent: If ``True``, suppress all event logs and warnings from MLflow during Langchain
autologging. If ``False``, show all events and warnings during Langchain
autologging.
log_traces: If ``True``, traces are logged for Langchain models by using
MlflowLangchainTracer as a callback during inference. If ``False``, no traces are
collected during inference. Default to ``True``.
run_tracer_inline: If ``True``, the MLflow tracer callback runs in the main async task
rather than being offloaded to a thread pool. This ensures proper context propagation
when combining autolog traces with manual ``@mlflow.trace`` decorators in async
scenarios (e.g., LangGraph's ``ainvoke``). Default is ``False`` for backward
compatibility. Set to ``True`` if you use manual ``@mlflow.trace`` decorators within
LangGraph nodes or tools and need them properly nested in the autolog trace.
load_model(model_uri, dst_path=None)
.. Note:: The 'langchain' MLflow Models integration is known to be compatible with ``1.0.0`` <= ``langchain`` <= ``1.3.14``. MLflow Models integrations with langchain may not succeed when used with package versions outside of this range.
Load a LangChain model from a local file or a run.
Args:
model_uri: The location, in URI format, of the MLflow model. For example:
- ``/Users/me/path/to/local/model``
- ``relative/path/to/local/model``
- ``s3://my_bucket/path/to/model``
- ``runs:/<mlflow_run_id>/run-relative/path/to/model``
For more information about supported URI schemes, see
`Referencing Artifacts <https://www.mlflow.org/docs/latest/tracking.html#
artifact-locations>`_.
dst_path: The local filesystem path to which to download the model artifact.
This directory must already exist. If unspecified, a local output
path will be created.
Returns:
A LangChain model instance.
log_model(lc_model, artifact_path: str | None = None, conda_env=None, code_paths=None, registered_model_name=None, signature: mlflow.models.signature.ModelSignature = None, input_example: Union[pandas.core.frame.DataFrame, numpy.ndarray, dict, list, ForwardRef('csr_matrix'), ForwardRef('csc_matrix'), str, bytes, tuple] = None, await_registration_for=300, pip_requirements=None, extra_pip_requirements=None, metadata=None, loader_fn=None, persist_dir=None, run_id=None, model_config=None, streamable=None, resources: list[mlflow.models.resources.Resource] | str | None = None, prompts: list[str | mlflow.entities.model_registry.prompt.Prompt] | None = None, name: str | None = None, params: dict[str, typing.Any] | None = None, tags: dict[str, typing.Any] | None = None, model_type: str | None = None, step: int = 0, model_id: str | None = None)
.. Note:: The 'langchain' MLflow Models integration is known to be compatible with ``1.0.0`` <= ``langchain`` <= ``1.3.14``. MLflow Models integrations with langchain may not succeed when used with package versions outside of this range.
Log a LangChain model as an MLflow artifact for the current run.
Args:
lc_model: A LangChain model, which could be a
`Chain <https://python.langchain.com/docs/modules/chains/>`_,
`Agent <https://python.langchain.com/docs/modules/agents/>`_, or
`retriever <https://python.langchain.com/docs/modules/data_connection/retrievers/>`_
or a path containing the `LangChain model code <https://github.com/mlflow/mlflow/blob/master/examples/langchain/chain_as_code_driver.py>`
for the above types. When using model as path, make sure to set the model
by using :func:`mlflow.models.set_model()`.
.. Note:: Experimental: Using model as path may change or be removed in a future
release without warning.
artifact_path: Deprecated. Use `name` instead.
conda_env: Either a dictionary representation of a Conda environment or the path to a conda
environment yaml file. If provided, this describes the environment this model should be run in.
At a minimum, it should specify the dependencies contained in `get_default_conda_env()`.
If ``None``, a conda environment with pip requirements inferred by
:func:`mlflow.models.infer_pip_requirements` is added
to the model. If the requirement inference fails, it falls back to using
`get_default_pip_requirements`. pip requirements from ``conda_env`` are written to a pip
``requirements.txt`` file and the full conda environment is written to ``conda.yaml``.
The following is an *example* dictionary representation of a conda environment::
{
"name": "mlflow-env",
"channels": ["conda-forge"],
"dependencies": [
"python=3.8.15",
{
"pip": [
"langchain==x.y.z"
],
},
],
}
code_paths: A list of local filesystem paths to Python file dependencies (or directories
containing file dependencies). These files are *prepended* to the system path when the model
is loaded. Files declared as dependencies for a given model should have relative
imports declared from a common root path if multiple files are defined with import dependencies
between them to avoid import errors when loading the model.
For a detailed explanation of ``code_paths`` functionality, recommended usage patterns and
limitations, see the
`code_paths usage guide <https://mlflow.org/docs/latest/model/dependencies.html?highlight=code_paths#saving-extra-code-with-an-mlflow-model>`_.
registered_model_name: If given, create a model
version under ``registered_model_name``, also creating a
registered model if one with the given name does not exist.
signature: :py:class:`ModelSignature <mlflow.models.ModelSignature>`
describes model input and output
:py:class:`Schema <mlflow.types.Schema>`.
If not specified, the model signature would be set according to
`lc_model.input_keys` and `lc_model.output_keys` as columns names, and
`DataType.string` as the column type.
Alternatively, you can explicitly specify the model signature.
The model signature can be :py:func:`inferred
<mlflow.models.infer_signature>` from datasets with valid model input
(e.g. the training dataset with target column omitted) and valid model
output (e.g. model predictions generated on the training dataset),
for example:
.. code-block:: python
from mlflow.models import infer_signature
chain = LLMChain(llm=llm, prompt=prompt)
prediction = chain.run(input_str)
input_columns = [
{"type": "string", "name": input_key} for input_key in chain.input_keys
]
signature = infer_signature(input_columns, predictions)
input_example: one or several instances of valid model input. The input example is used
as a hint of what data to feed the model. It will be converted to a Pandas
DataFrame and then serialized to json using the Pandas split-oriented
format, or a numpy array where the example will be serialized to json
by converting it to a list. Bytes are base64-encoded. When the ``signature`` parameter is
``None``, the input example is used to infer a model signature.
await_registration_for: Number of seconds to wait for the model version
to finish being created and is in ``READY`` status.
By default, the function waits for five minutes.
Specify 0 or None to skip waiting.
pip_requirements: Either an iterable of pip requirement strings
(e.g. ``["langchain", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes the environment this model should be run in. If ``None``, a default list of requirements
is inferred by :func:`mlflow.models.infer_pip_requirements` from the current software environment.
If the requirement inference fails, it falls back to using `get_default_pip_requirements`.
Both requirements and constraints are automatically parsed and written to ``requirements.txt`` and
``constraints.txt`` files, respectively, and stored as part of the model. Requirements are also
written to the ``pip`` section of the model's conda environment (``conda.yaml``) file.
extra_pip_requirements: Either an iterable of pip
requirement strings
(e.g. ``["pandas", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes additional pip requirements that are appended to a default set of pip requirements
generated automatically based on the user's current software environment. Both requirements and
constraints are automatically parsed and written to ``requirements.txt`` and ``constraints.txt``
files, respectively, and stored as part of the model. Requirements are also written to the ``pip``
section of the model's conda environment (``conda.yaml``) file.
.. warning::
The following arguments can't be specified at the same time:
- ``conda_env``
- ``pip_requirements``
- ``extra_pip_requirements``
`This example <https://github.com/mlflow/mlflow/blob/master/examples/pip_requirements/pip_requirements.py>`_ demonstrates how to specify pip requirements using
``pip_requirements`` and ``extra_pip_requirements``.
metadata: Custom metadata dictionary passed to the model and stored in the MLmodel file.
loader_fn: A function that's required for models containing objects that aren't natively
serialized by LangChain.
This function takes a string `persist_dir` as an argument and returns the
specific object that the model needs. Depending on the model,
this could be a retriever, vectorstore, requests_wrapper, embeddings, or
database. For RetrievalQA Chain and retriever models, the object is a
(`retriever <https://python.langchain.com/docs/modules/data_connection/retrievers/>`_).
For APIChain models, it's a
(`requests_wrapper <https://python.langchain.com/docs/modules/agents/tools/integrations/requests>`_).
For HypotheticalDocumentEmbedder models, it's an
(`embeddings <https://python.langchain.com/docs/modules/data_connection/text_embedding/>`_).
For SQLDatabaseChain models, it's a
(`database <https://python.langchain.com/docs/modules/agents/toolkits/sql_database>`_).
persist_dir: The directory where the object is stored. The `loader_fn`
takes this string as the argument to load the object.
This is optional for models containing objects that aren't natively
serialized by LangChain. MLflow logs the content in this directory as
artifacts in the subdirectory named `persist_dir_data`.
Here is the code snippet for logging a RetrievalQA chain with `loader_fn`
and `persist_dir`:
.. Note:: In langchain_community >= 0.0.27, loading pickled data requires providing the
``allow_dangerous_deserialization`` argument.
.. code-block:: python
qa = RetrievalQA.from_llm(llm=OpenAI(), retriever=db.as_retriever())
def load_retriever(persist_directory):
embeddings = OpenAIEmbeddings()
vectorstore = FAISS.load_local(
persist_directory,
embeddings,
# you may need to add the line below
# for langchain_community >= 0.0.27
allow_dangerous_deserialization=True,
)
return vectorstore.as_retriever()
with mlflow.start_run() as run:
logged_model = mlflow.langchain.log_model(
qa,
name="retrieval_qa",
loader_fn=load_retriever,
persist_dir=persist_dir,
)
See a complete example in examples/langchain/retrieval_qa_chain.py.
run_id: run_id to associate with this model version. If specified, we resume the
run and log the model to that run. Otherwise, a new run is created.
Default to None.
model_config: The model configuration to apply to the model if saving model from code. This
configuration is available during model loading.
.. Note:: Experimental: This parameter may change or be removed in a future
release without warning.
streamable: A boolean value indicating if the model supports streaming prediction. If
True, the model must implement `stream` method. If None, If None, streamable is
set to True if the model implements `stream` method. Default to `None`.
resources: A list of model resources or a resources.yaml file containing a list of
resources required to serve the model. If logging a LangChain model with dependencies
(e.g. on LLM model serving endpoints), we encourage explicitly passing dependencies
via this parameter. Otherwise, ``log_model`` will attempt to infer dependencies,
but dependency auto-inference is best-effort and may miss some dependencies.
prompts: A list of prompt URIs registered in the MLflow Prompt Registry, to be associated with the model.
Each prompt URI should be in the form ``prompt:/<name>/<version>``. The prompts should be
registered in the MLflow Prompt Registry before being associated with the model.
This will create a mutual link between the model and the prompt. The associated prompts can be
seen in the model's metadata stored in the MLmodel file. From the Prompt Registry UI, you can
navigate to the model as well.
.. code-block:: python
import mlflow
prompt_template = "Hi, {name}! How are you doing today?"
# Register a prompt in the MLflow Prompt Registry
mlflow.prompts.register_prompt("my_prompt", prompt_template, description="A simple prompt")
# Log a model with the registered prompt
with mlflow.start_run():
model_info = mlflow.pyfunc.log_model(
name=MyModel(),
name="model",
prompts=["prompt:/my_prompt/1"]
)
print(model_info.prompts)
# Output: ['prompt:/my_prompt/1']
# Load the prompt
prompt = mlflow.genai.load_prompt(model_info.prompts[0])
name: Model name.
params: A dictionary of parameters to log with the model.
tags: A dictionary of tags to log with the model.
model_type: The type of the model.
step: The step at which to log the model outputs and metrics
model_id: The ID of the model.
Returns:
A :py:class:`ModelInfo <mlflow.models.model.ModelInfo>` instance that contains the
metadata of the logged model.
save_model(lc_model, path, conda_env=None, code_paths=None, mlflow_model=None, signature: mlflow.models.signature.ModelSignature = None, input_example: Union[pandas.core.frame.DataFrame, numpy.ndarray, dict, list, ForwardRef('csr_matrix'), ForwardRef('csc_matrix'), str, bytes, tuple] = None, pip_requirements=None, extra_pip_requirements=None, metadata=None, loader_fn=None, persist_dir=None, model_config=None, streamable: bool | None = None)
.. Note:: The 'langchain' MLflow Models integration is known to be compatible with ``1.0.0`` <= ``langchain`` <= ``1.3.14``. MLflow Models integrations with langchain may not succeed when used with package versions outside of this range.
Save a LangChain model to a path on the local file system.
Args:
lc_model: A LangChain model, which could be a
`Chain <https://python.langchain.com/docs/modules/chains/>`_,
`Agent <https://python.langchain.com/docs/modules/agents/>`_,
`retriever <https://python.langchain.com/docs/modules/data_connection/retrievers/>`_,
or `RunnableSequence <https://python.langchain.com/docs/modules/chains/foundational/sequential_chains#using-lcel>`_,
or a path containing the `LangChain model code <https://github.com/mlflow/mlflow/blob/master/examples/langchain/chain_as_code_driver.py>`
for the above types. When using model as path, make sure to set the model
by using :func:`mlflow.models.set_model()`.
.. Note:: Experimental: Using model as path may change or be removed in a future
release without warning.
path: Local path where the serialized model (as YAML) is to be saved.
conda_env: Either a dictionary representation of a Conda environment or the path to a conda
environment yaml file. If provided, this describes the environment this model should be run in.
At a minimum, it should specify the dependencies contained in `get_default_conda_env()`.
If ``None``, a conda environment with pip requirements inferred by
:func:`mlflow.models.infer_pip_requirements` is added
to the model. If the requirement inference fails, it falls back to using
`get_default_pip_requirements`. pip requirements from ``conda_env`` are written to a pip
``requirements.txt`` file and the full conda environment is written to ``conda.yaml``.
The following is an *example* dictionary representation of a conda environment::
{
"name": "mlflow-env",
"channels": ["conda-forge"],
"dependencies": [
"python=3.8.15",
{
"pip": [
"langchain==x.y.z"
],
},
],
}
code_paths: A list of local filesystem paths to Python file dependencies (or directories
containing file dependencies). These files are *prepended* to the system path when the model
is loaded. Files declared as dependencies for a given model should have relative
imports declared from a common root path if multiple files are defined with import dependencies
between them to avoid import errors when loading the model.
For a detailed explanation of ``code_paths`` functionality, recommended usage patterns and
limitations, see the
`code_paths usage guide <https://mlflow.org/docs/latest/model/dependencies.html?highlight=code_paths#saving-extra-code-with-an-mlflow-model>`_.
mlflow_model: :py:mod:`mlflow.models.Model` this flavor is being added to.
signature: :py:class:`ModelSignature <mlflow.models.ModelSignature>`
describes model input and output :py:class:`Schema <mlflow.types.Schema>`.
If not specified, the model signature would be set according to
`lc_model.input_keys` and `lc_model.output_keys` as columns names, and
`DataType.string` as the column type.
Alternatively, you can explicitly specify the model signature.
The model signature can be :py:func:`inferred <mlflow.models.infer_signature>`
from datasets with valid model input (e.g. the training dataset with target
column omitted) and valid model output (e.g. model predictions generated on
the training dataset), for example:
.. code-block:: python
from mlflow.models import infer_signature
chain = LLMChain(llm=llm, prompt=prompt)
prediction = chain.run(input_str)
input_columns = [
{"type": "string", "name": input_key} for input_key in chain.input_keys
]
signature = infer_signature(input_columns, predictions)
input_example: one or several instances of valid model input. The input example is used
as a hint of what data to feed the model. It will be converted to a Pandas
DataFrame and then serialized to json using the Pandas split-oriented
format, or a numpy array where the example will be serialized to json
by converting it to a list. Bytes are base64-encoded. When the ``signature`` parameter is
``None``, the input example is used to infer a model signature.
pip_requirements: Either an iterable of pip requirement strings
(e.g. ``["langchain", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes the environment this model should be run in. If ``None``, a default list of requirements
is inferred by :func:`mlflow.models.infer_pip_requirements` from the current software environment.
If the requirement inference fails, it falls back to using `get_default_pip_requirements`.
Both requirements and constraints are automatically parsed and written to ``requirements.txt`` and
``constraints.txt`` files, respectively, and stored as part of the model. Requirements are also
written to the ``pip`` section of the model's conda environment (``conda.yaml``) file.
extra_pip_requirements: Either an iterable of pip
requirement strings
(e.g. ``["pandas", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes additional pip requirements that are appended to a default set of pip requirements
generated automatically based on the user's current software environment. Both requirements and
constraints are automatically parsed and written to ``requirements.txt`` and ``constraints.txt``
files, respectively, and stored as part of the model. Requirements are also written to the ``pip``
section of the model's conda environment (``conda.yaml``) file.
.. warning::
The following arguments can't be specified at the same time:
- ``conda_env``
- ``pip_requirements``
- ``extra_pip_requirements``
`This example <https://github.com/mlflow/mlflow/blob/master/examples/pip_requirements/pip_requirements.py>`_ demonstrates how to specify pip requirements using
``pip_requirements`` and ``extra_pip_requirements``.
metadata: Custom metadata dictionary passed to the model and stored in the MLmodel file.
loader_fn: A function that's required for models containing objects that aren't natively
serialized by LangChain.
This function takes a string `persist_dir` as an argument and returns the
specific object that the model needs. Depending on the model,
this could be a retriever, vectorstore, requests_wrapper, embeddings, or
database. For RetrievalQA Chain and retriever models, the object is a
(`retriever <https://python.langchain.com/docs/modules/data_connection/retrievers/>`_).
For APIChain models, it's a
(`requests_wrapper <https://python.langchain.com/docs/modules/agents/tools/integrations/requests>`_).
For HypotheticalDocumentEmbedder models, it's an
(`embeddings <https://python.langchain.com/docs/modules/data_connection/text_embedding/>`_).
For SQLDatabaseChain models, it's a
(`database <https://python.langchain.com/docs/modules/agents/toolkits/sql_database>`_).
persist_dir: The directory where the object is stored. The `loader_fn`
takes this string as the argument to load the object.
This is optional for models containing objects that aren't natively
serialized by LangChain. MLflow logs the content in this directory as
artifacts in the subdirectory named `persist_dir_data`.
Here is the code snippet for logging a RetrievalQA chain with `loader_fn`
and `persist_dir`:
.. Note:: In langchain_community >= 0.0.27, loading pickled data requires providing the
``allow_dangerous_deserialization`` argument.
.. code-block:: python
qa = RetrievalQA.from_llm(llm=OpenAI(), retriever=db.as_retriever())
def load_retriever(persist_directory):
embeddings = OpenAIEmbeddings()
vectorstore = FAISS.load_local(
persist_directory,
embeddings,
# you may need to add the line below
# for langchain_community >= 0.0.27
allow_dangerous_deserialization=True,
)
return vectorstore.as_retriever()
with mlflow.start_run() as run:
logged_model = mlflow.langchain.log_model(
qa,
name="retrieval_qa",
loader_fn=load_retriever,
persist_dir=persist_dir,
)
See a complete example in examples/langchain/retrieval_qa_chain.py.
model_config: The model configuration to apply to the model if saving model from code. This
configuration is available during model loading.
.. Note:: Experimental: This parameter may change or be removed in a future
release without warning.
streamable: A boolean value indicating if the model supports streaming prediction. If
True, the model must implement `stream` method. If None, streamable is
set to True if the model implements `stream` method. Default to `None`.
DATA
FLAVOR_NAME = 'langchain'
__all__ = ['autolog', 'FLAVOR_NAME', '_LangChainModelWrapper', '_load_...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\langchain\__init__.py
mlflow.last_active_run
Python Library Documentation: function last_active_run in module mlflow.tracking.fluent
last_active_run() -> mlflow.entities.run.Run | None
Gets the most recent active run.
Examples:
.. code-block:: python
:test:
:caption: To retrieve the most recent autologged run:
import mlflow
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_diabetes
from sklearn.ensemble import RandomForestRegressor
mlflow.autolog()
db = load_diabetes()
X_train, X_test, y_train, y_test = train_test_split(db.data, db.target)
# Create and train models.
rf = RandomForestRegressor(n_estimators=100, max_depth=6, max_features=3)
rf.fit(X_train, y_train)
# Use the model to make predictions on the test dataset.
predictions = rf.predict(X_test)
autolog_run = mlflow.last_active_run()
.. code-block:: python
:test:
:caption: To get the most recently active run that ended:
import mlflow
mlflow.start_run()
mlflow.end_run()
run = mlflow.last_active_run()
.. code-block:: python
:test:
:caption: To retrieve the currently active run:
import mlflow
mlflow.start_run()
run = mlflow.last_active_run()
mlflow.end_run()
Returns:
The active run (this is equivalent to ``mlflow.active_run()``) if one exists.
Otherwise, the last run started from the current Python process that reached
a terminal status (i.e. FINISHED, FAILED, or KILLED).
mlflow.last_logged_model
Python Library Documentation: function last_logged_model in module mlflow.tracking.fluent
last_logged_model() -> mlflow.entities.logged_model.LoggedModel | None
Fetches the most recent logged model in the current session.
If no model has been logged, None is returned.
Returns:
The logged model.
.. code-block:: python
:test:
:caption: Example
import mlflow
class DummyModel(mlflow.pyfunc.PythonModel):
def predict(self, context, model_input: list[str]) -> list[str]:
return model_input
model_info = mlflow.pyfunc.log_model(name="model", python_model=DummyModel())
last_model = mlflow.last_logged_model()
assert last_model.model_id == model_info.model_id
mlflow.legacy_databricks_cli
Python Library Documentation: package mlflow.legacy_databricks_cli in mlflow
NAME
mlflow.legacy_databricks_cli
PACKAGE CONTENTS
configure (package)
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\legacy_databricks_cli\__init__.py
mlflow.lightgbm
Python Library Documentation: package mlflow.lightgbm in mlflow
NAME
mlflow.lightgbm
DESCRIPTION
The ``mlflow.lightgbm`` module provides an API for logging and loading LightGBM models.
This module exports LightGBM models with the following flavors:
LightGBM (native) format
This is the main flavor that can be loaded back into LightGBM.
:py:mod:`mlflow.pyfunc`
Produced for use by generic pyfunc-based deployment tools and batch inference.
.. _lightgbm.Booster:
https://lightgbm.readthedocs.io/en/latest/pythonapi/lightgbm.Booster.html#lightgbm.Booster
.. _lightgbm.Booster.save_model:
https://lightgbm.readthedocs.io/en/latest/pythonapi/lightgbm.Booster.html
#lightgbm.Booster.save_model
.. _lightgbm.train:
https://lightgbm.readthedocs.io/en/latest/pythonapi/lightgbm.train.html#lightgbm-train
.. _scikit-learn API:
https://lightgbm.readthedocs.io/en/latest/Python-API.html#scikit-learn-api
PACKAGE CONTENTS
DATA
DEFAULT_AWAIT_MAX_SLEEP_SECONDS = 300
ENSURE_AUTOLOGGING_ENABLED_TEXT = 'please ensure that autologging is e...
FLAVOR_NAME = 'lightgbm'
INPUT_EXAMPLE_SAMPLE_ROWS = 5
LOG_MODEL_PARAM_DOCS = ParamDocs({'name': 'Model name.', 'conda_env': ...
MLFLOW_DATASET_CONTEXT = 'mlflow.data.context'
MLMODEL_FILE_NAME = 'MLmodel'
ModelInputExample = typing.Union[pandas.core.frame.DataFrame, numpy......
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\lightgbm\__init__.py
mlflow.list_workspaces
Python Library Documentation: function list_workspaces in module mlflow.tracking._workspace.fluent
list_workspaces() -> 'list[Workspace]'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Return the list of workspaces available to the current user.
mlflow.litellm
Python Library Documentation: package mlflow.litellm in mlflow
NAME
mlflow.litellm
PACKAGE CONTENTS
DATA
Callable = typing.Callable
Deprecated alias to collections.abc.Callable.
Callable[[int], str] signifies a function that takes a single
parameter of type int and returns a str.
The subscription syntax must always be used with exactly two
values: the argument list and the return type.
The argument list must be a list of types, a ParamSpec,
Concatenate or ellipsis. The return type must be a single type.
There is no syntax to indicate optional or keyword arguments;
such function types are rarely used as callback types.
FLAVOR_NAME = 'litellm'
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\litellm\__init__.py
mlflow.llama_index
Python Library Documentation: package mlflow.llama_index in mlflow
NAME
mlflow.llama_index
PACKAGE CONTENTS
autolog
constant
model
pyfunc_wrapper
serialize_objects
tracer
FUNCTIONS
_load_pyfunc(path, model_config: dict[str, typing.Any] | None = None)
autolog(log_traces: bool = True, disable: bool = False, silent: bool = False)
Enables (or disables) and configures autologging from LlamaIndex to MLflow. Currently, MLflow
only supports autologging for tracing.
Args:
log_traces: If ``True``, traces are logged for LlamaIndex models by using. If ``False``,
no traces are collected during inference. Default to ``True``.
disable: If ``True``, disables the LlamaIndex autologging integration. If ``False``,
enables the LlamaIndex autologging integration.
silent: If ``True``, suppress all event logs and warnings from MLflow during LlamaIndex
autologging. If ``False``, show all events and warnings.
load_model(model_uri, dst_path=None)
Load a LlamaIndex index/engine/workflow from a local file or a run.
Args:
model_uri: The location, in URI format, of the MLflow model. For example:
- ``/Users/me/path/to/local/model``
- ``relative/path/to/local/model``
- ``s3://my_bucket/path/to/model``
- ``runs:/<mlflow_run_id>/run-relative/path/to/model``
- ``mlflow-artifacts:/path/to/model``
For more information about supported URI schemes, see
`Referencing Artifacts <https://www.mlflow.org/docs/latest/tracking.html#
artifact-locations>`_.
dst_path: The local filesystem path to utilize for downloading the model artifact.
This directory must already exist if provided. If unspecified, a local output
path will be created.
Returns:
A LlamaIndex index object.
log_model(llama_index_model, artifact_path: str | None = None, engine_type: str | None = None, model_config: dict[str, typing.Any] | None = None, code_paths: list[str] | None = None, registered_model_name: str | None = None, signature: mlflow.models.signature.ModelSignature | None = None, input_example: Union[pandas.core.frame.DataFrame, numpy.ndarray, dict, list, ForwardRef('csr_matrix'), ForwardRef('csc_matrix'), str, bytes, tuple, NoneType] = None, await_registration_for=300, pip_requirements: list[str] | str | None = None, extra_pip_requirements: list[str] | str | None = None, conda_env=None, metadata: dict[str, typing.Any] | None = None, prompts: list[str | mlflow.entities.model_registry.prompt.Prompt] | None = None, name: str | None = None, params: dict[str, typing.Any] | None = None, tags: dict[str, typing.Any] | None = None, model_type: str | None = None, step: int = 0, model_id: str | None = None, **kwargs)
Log a LlamaIndex model as an MLflow artifact for the current run.
.. attention::
Saving a non-index object is only supported in the 'Model-from-Code' saving mode.
Please refer to the `Models From Code Guide <https://www.mlflow.org/docs/latest/model/models-from-code.html>`_
for more information.
.. note::
When logging a model, MLflow will automatically save the state of the ``Settings``
object so that you can use the same settings at inference time. However, please
note that some information in the ``Settings`` object will not be saved, including:
- API keys for avoiding key leakage.
- Function objects which are not serializable.
Args:
llama_index_model: A LlamaIndex object to be saved. Supported model types are:
1. An Index object.
2. An Engine object e.g. ChatEngine, QueryEngine, Retriever.
3. A `Workflow <https://docs.llamaindex.ai/en/stable/module_guides/workflow/>`_ object.
4. A string representing the path to a script contains LlamaIndex model definition
of the one of the above types.
artifact_path: Deprecated. Use `name` instead.
engine_type: Required when saving an Index object to determine the inference interface
for the index when loaded as a pyfunc model. This field is **not** required when
saving other LlamaIndex objects. The supported values are as follows:
- ``"chat"``: load the index as an instance of the LlamaIndex
`ChatEngine <https://docs.llamaindex.ai/en/stable/module_guides/deploying/chat_engines/>`_.
- ``"query"``: load the index as an instance of the LlamaIndex
`QueryEngine <https://docs.llamaindex.ai/en/stable/module_guides/deploying/query_engine/>`_.
- ``"retriever"``: load the index as an instance of the LlamaIndex
`Retriever <https://docs.llamaindex.ai/en/stable/module_guides/querying/retriever/>`_.
model_config: The model configuration to apply when loading the model back with
``mlflow.pyfunc.load_model()``. It will be applied in a different way depending on the
model type and saving method:
For in-memory Index objects saved directly, it will be passed as keyword arguments to
instantiate the LlamaIndex engine with the specified engine type at logging.
.. code-block:: python
with mlflow.start_run() as run:
model_info = mlflow.llama_index.log_model(
index,
name="index",
engine_type="chat",
model_config={"top_k": 10},
)
# When loading back, MLflow will call ``index.as_chat_engine(top_k=10)``
engine = mlflow.pyfunc.load_model(model_info.model_uri)
For other model types saved with the `Model-from-Code <https://www.mlflow.org/docs/latest/model/models-from-code.html>`
method, the config will be accessed via the :py:class`~mlflow.models.ModelConfig`
object within your model code.
.. code-block:: python
with mlflow.start_run() as run:
model_info = mlflow.llama_index.log_model(
"model.py",
name="model",
model_config={"qdrant_host": "localhost", "qdrant_port": 6333},
)
model.py:
.. code-block:: python
import mlflow
from llama_index.vector_stores.qdrant import QdrantVectorStore
import qdrant_client
# The model configuration is accessible via the ModelConfig singleton
model_config = mlflow.models.ModelConfig()
qdrant_host = model_config.get("top_k", 5)
qdrant_port = model_config.get("qdrant_port", 6333)
client = qdrant_client.Client(host=qdrant_host, port=qdrant_port)
vectorstore = QdrantVectorStore(client)
# the rest of the model definition...
code_paths: A list of local filesystem paths to Python file dependencies (or directories
containing file dependencies). These files are *prepended* to the system path when the model
is loaded. Files declared as dependencies for a given model should have relative
imports declared from a common root path if multiple files are defined with import dependencies
between them to avoid import errors when loading the model.
For a detailed explanation of ``code_paths`` functionality, recommended usage patterns and
limitations, see the
`code_paths usage guide <https://mlflow.org/docs/latest/model/dependencies.html?highlight=code_paths#saving-extra-code-with-an-mlflow-model>`_.
registered_model_name: If given, create a model
version under ``registered_model_name``, also creating a
registered model if one with the given name does not exist.
signature: A Model Signature object that describes the input and output Schema of the
model. The model signature can be inferred using ``infer_signature`` function
of `mlflow.models.signature`.
input_example: one or several instances of valid model input. The input example is used
as a hint of what data to feed the model. It will be converted to a Pandas
DataFrame and then serialized to json using the Pandas split-oriented
format, or a numpy array where the example will be serialized to json
by converting it to a list. Bytes are base64-encoded. When the ``signature`` parameter is
``None``, the input example is used to infer a model signature.
await_registration_for: Number of seconds to wait for the model version
to finish being created and is in ``READY`` status.
By default, the function waits for five minutes.
Specify 0 or None to skip waiting.
pip_requirements: Either an iterable of pip requirement strings
(e.g. ``["llama_index", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes the environment this model should be run in. If ``None``, a default list of requirements
is inferred by :func:`mlflow.models.infer_pip_requirements` from the current software environment.
If the requirement inference fails, it falls back to using `get_default_pip_requirements`.
Both requirements and constraints are automatically parsed and written to ``requirements.txt`` and
``constraints.txt`` files, respectively, and stored as part of the model. Requirements are also
written to the ``pip`` section of the model's conda environment (``conda.yaml``) file.
extra_pip_requirements: Either an iterable of pip
requirement strings
(e.g. ``["pandas", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes additional pip requirements that are appended to a default set of pip requirements
generated automatically based on the user's current software environment. Both requirements and
constraints are automatically parsed and written to ``requirements.txt`` and ``constraints.txt``
files, respectively, and stored as part of the model. Requirements are also written to the ``pip``
section of the model's conda environment (``conda.yaml``) file.
.. warning::
The following arguments can't be specified at the same time:
- ``conda_env``
- ``pip_requirements``
- ``extra_pip_requirements``
`This example <https://github.com/mlflow/mlflow/blob/master/examples/pip_requirements/pip_requirements.py>`_ demonstrates how to specify pip requirements using
``pip_requirements`` and ``extra_pip_requirements``.
conda_env: Either a dictionary representation of a Conda environment or the path to a conda
environment yaml file. If provided, this describes the environment this model should be run in.
At a minimum, it should specify the dependencies contained in `get_default_conda_env()`.
If ``None``, a conda environment with pip requirements inferred by
:func:`mlflow.models.infer_pip_requirements` is added
to the model. If the requirement inference fails, it falls back to using
`get_default_pip_requirements`. pip requirements from ``conda_env`` are written to a pip
``requirements.txt`` file and the full conda environment is written to ``conda.yaml``.
The following is an *example* dictionary representation of a conda environment::
{
"name": "mlflow-env",
"channels": ["conda-forge"],
"dependencies": [
"python=3.8.15",
{
"pip": [
"llama_index==x.y.z"
],
},
],
}
metadata: Custom metadata dictionary passed to the model and stored in the MLmodel file.
prompts: A list of prompt URIs registered in the MLflow Prompt Registry, to be associated with the model.
Each prompt URI should be in the form ``prompt:/<name>/<version>``. The prompts should be
registered in the MLflow Prompt Registry before being associated with the model.
This will create a mutual link between the model and the prompt. The associated prompts can be
seen in the model's metadata stored in the MLmodel file. From the Prompt Registry UI, you can
navigate to the model as well.
.. code-block:: python
import mlflow
prompt_template = "Hi, {name}! How are you doing today?"
# Register a prompt in the MLflow Prompt Registry
mlflow.prompts.register_prompt("my_prompt", prompt_template, description="A simple prompt")
# Log a model with the registered prompt
with mlflow.start_run():
model_info = mlflow.pyfunc.log_model(
name=MyModel(),
name="model",
prompts=["prompt:/my_prompt/1"]
)
print(model_info.prompts)
# Output: ['prompt:/my_prompt/1']
# Load the prompt
prompt = mlflow.genai.load_prompt(model_info.prompts[0])
name: Model name.
params: A dictionary of parameters to log with the model.
tags: A dictionary of tags to log with the model.
model_type: The type of the model.
step: The step at which to log the model outputs and metrics
model_id: The ID of the model.
kwargs: Additional arguments for :py:class:`mlflow.models.model.Model`
save_model(llama_index_model, path: str, engine_type: str | None = None, model_config: str | dict[str, typing.Any] | None = None, code_paths=None, mlflow_model: mlflow.models.model.Model | None = None, signature: mlflow.models.signature.ModelSignature | None = None, input_example: Union[pandas.core.frame.DataFrame, numpy.ndarray, dict, list, ForwardRef('csr_matrix'), ForwardRef('csc_matrix'), str, bytes, tuple, NoneType] = None, pip_requirements: list[str] | str | None = None, extra_pip_requirements: list[str] | str | None = None, conda_env=None, metadata: dict[str, typing.Any] | None = None) -> None
Save a LlamaIndex model to a path on the local file system.
.. attention::
Saving a non-index object is only supported in the 'Model-from-Code' saving mode.
Please refer to the `Models From Code Guide <https://www.mlflow.org/docs/latest/model/models-from-code.html>`_
for more information.
.. note::
When logging a model, MLflow will automatically save the state of the ``Settings``
object so that you can use the same settings at inference time. However, please
note that some information in the ``Settings`` object will not be saved, including:
- API keys for avoiding key leakage.
- Function objects which are not serializable.
Args:
llama_index_model: A LlamaIndex object to be saved. Supported model types are:
1. An Index object.
2. An Engine object e.g. ChatEngine, QueryEngine, Retriever.
3. A `Workflow <https://docs.llamaindex.ai/en/stable/module_guides/workflow/>`_ object.
4. A string representing the path to a script contains LlamaIndex model definition
of the one of the above types.
path: Local path where the serialized model (as YAML) is to be saved.
engine_type: Required when saving an Index object to determine the inference interface
for the index when loaded as a pyfunc model. This field is **not** required when
saving other LlamaIndex objects. The supported values are as follows:
- ``"chat"``: load the index as an instance of the LlamaIndex
`ChatEngine <https://docs.llamaindex.ai/en/stable/module_guides/deploying/chat_engines/>`_.
- ``"query"``: load the index as an instance of the LlamaIndex
`QueryEngine <https://docs.llamaindex.ai/en/stable/module_guides/deploying/query_engine/>`_.
- ``"retriever"``: load the index as an instance of the LlamaIndex
`Retriever <https://docs.llamaindex.ai/en/stable/module_guides/querying/retriever/>`_.
model_config: The model configuration to apply when loading the model back with
``mlflow.pyfunc.load_model()``. It will be applied in a different way depending on the
model type and saving method. See the docstring of :func:`log_model` for more details
and usage examples.
code_paths: A list of local filesystem paths to Python file dependencies (or directories
containing file dependencies). These files are *prepended* to the system path when the model
is loaded. Files declared as dependencies for a given model should have relative
imports declared from a common root path if multiple files are defined with import dependencies
between them to avoid import errors when loading the model.
For a detailed explanation of ``code_paths`` functionality, recommended usage patterns and
limitations, see the
`code_paths usage guide <https://mlflow.org/docs/latest/model/dependencies.html?highlight=code_paths#saving-extra-code-with-an-mlflow-model>`_.
mlflow_model: An MLflow model object that specifies the flavor that this model is being
added to.
signature: A Model Signature object that describes the input and output Schema of the
model. The model signature can be inferred using ``infer_signature`` function
of ``mlflow.models.signature``.
input_example: one or several instances of valid model input. The input example is used
as a hint of what data to feed the model. It will be converted to a Pandas
DataFrame and then serialized to json using the Pandas split-oriented
format, or a numpy array where the example will be serialized to json
by converting it to a list. Bytes are base64-encoded. When the ``signature`` parameter is
``None``, the input example is used to infer a model signature.
pip_requirements: Either an iterable of pip requirement strings
(e.g. ``["llama_index", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes the environment this model should be run in. If ``None``, a default list of requirements
is inferred by :func:`mlflow.models.infer_pip_requirements` from the current software environment.
If the requirement inference fails, it falls back to using `get_default_pip_requirements`.
Both requirements and constraints are automatically parsed and written to ``requirements.txt`` and
``constraints.txt`` files, respectively, and stored as part of the model. Requirements are also
written to the ``pip`` section of the model's conda environment (``conda.yaml``) file.
extra_pip_requirements: Either an iterable of pip
requirement strings
(e.g. ``["pandas", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes additional pip requirements that are appended to a default set of pip requirements
generated automatically based on the user's current software environment. Both requirements and
constraints are automatically parsed and written to ``requirements.txt`` and ``constraints.txt``
files, respectively, and stored as part of the model. Requirements are also written to the ``pip``
section of the model's conda environment (``conda.yaml``) file.
.. warning::
The following arguments can't be specified at the same time:
- ``conda_env``
- ``pip_requirements``
- ``extra_pip_requirements``
`This example <https://github.com/mlflow/mlflow/blob/master/examples/pip_requirements/pip_requirements.py>`_ demonstrates how to specify pip requirements using
``pip_requirements`` and ``extra_pip_requirements``.
conda_env: Either a dictionary representation of a Conda environment or the path to a conda
environment yaml file. If provided, this describes the environment this model should be run in.
At a minimum, it should specify the dependencies contained in `get_default_conda_env()`.
If ``None``, a conda environment with pip requirements inferred by
:func:`mlflow.models.infer_pip_requirements` is added
to the model. If the requirement inference fails, it falls back to using
`get_default_pip_requirements`. pip requirements from ``conda_env`` are written to a pip
``requirements.txt`` file and the full conda environment is written to ``conda.yaml``.
The following is an *example* dictionary representation of a conda environment::
{
"name": "mlflow-env",
"channels": ["conda-forge"],
"dependencies": [
"python=3.8.15",
{
"pip": [
"llama_index==x.y.z"
],
},
],
}
metadata: Custom metadata dictionary passed to the model and stored in the MLmodel file.
DATA
FLAVOR_NAME = 'llama_index'
__all__ = ['autolog', 'FLAVOR_NAME', 'load_model', 'log_model', 'save_...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\llama_index\__init__.py
mlflow.load_prompt
Python Library Documentation: function load_prompt in module mlflow.tracking._model_registry.fluent
load_prompt(name_or_uri: str, version: str | int | None = None, allow_missing: bool = False, link_to_model: bool = True, model_id: str | None = None, cache_ttl_seconds: float | None = None) -> mlflow.entities.model_registry.prompt_version.PromptVersion
Load a :py:class:`Prompt <mlflow.entities.Prompt>` from the MLflow Prompt Registry.
The prompt can be specified by name and version, or by URI.
Args:
name_or_uri: The name of the prompt, or the URI in the format "prompts:/name/version".
version: The version of the prompt (required when using name, not allowed when using URI).
allow_missing: If True, return None instead of raising Exception if the specified prompt
is not found.
link_to_model: If True, the prompt will be linked to the model with the ID specified
by `model_id`, or the active model ID if `model_id` is None and
there is an active model.
model_id: The ID of the model to which to link the prompt, if `link_to_model` is True.
cache_ttl_seconds: Time-to-live in seconds for the cached prompt. If not specified,
uses the value from `MLFLOW_ALIAS_PROMPT_CACHE_TTL_SECONDS` environment variable for
alias-based prompts (default 60), and the value from
`MLFLOW_VERSION_PROMPT_CACHE_TTL_SECONDS` environment variable for version-based prompts
(default None, no TTL). Set to 0 to bypass the cache and always fetch from the server.
Example:
.. code-block:: python
import mlflow
# Load a specific version of the prompt
prompt = mlflow.load_prompt("my_prompt", version=1)
# Load a specific version of the prompt by URI
prompt = mlflow.load_prompt("prompts:/my_prompt/1")
# Load a prompt version with an alias "production"
prompt = mlflow.load_prompt("prompts:/my_prompt@production")
# Load with custom cache TTL (5 minutes)
prompt = mlflow.load_prompt("my_prompt", version=1, cache_ttl_seconds=300)
# Bypass cache entirely
prompt = mlflow.load_prompt("my_prompt", version=1, cache_ttl_seconds=0)
mlflow.load_table
Python Library Documentation: function load_table in module mlflow.tracking.fluent
load_table(artifact_file: str, run_ids: list[str] | None = None, extra_columns: list[str] | None = None) -> 'pandas.DataFrame'
Load a table from MLflow Tracking as a pandas.DataFrame. The table is loaded from the
specified artifact_file in the specified run_ids. The extra_columns are columns that
are not in the table but are augmented with run information and added to the DataFrame.
Args:
artifact_file: The run-relative artifact file path in posixpath format to which
table to load (e.g. "dir/file.json").
run_ids: Optional list of run_ids to load the table from. If no run_ids are specified,
the table is loaded from all runs in the current experiment.
extra_columns: Optional list of extra columns to add to the returned DataFrame
For example, if extra_columns=["run_id"], then the returned DataFrame
will have a column named run_id.
Returns:
pandas.DataFrame containing the loaded table if the artifact exists
or else throw a MlflowException.
.. code-block:: python
:test:
:caption: Example with passing run_ids
import mlflow
table_dict = {
"inputs": ["What is MLflow?", "What is Databricks?"],
"outputs": ["MLflow is ...", "Databricks is ..."],
"toxicity": [0.0, 0.0],
}
with mlflow.start_run() as run:
# Log the dictionary as a table
mlflow.log_table(data=table_dict, artifact_file="qabot_eval_results.json")
run_id = run.info.run_id
loaded_table = mlflow.load_table(
artifact_file="qabot_eval_results.json",
run_ids=[run_id],
# Append a column containing the associated run ID for each row
extra_columns=["run_id"],
)
.. code-block:: python
:test:
:caption: Example with passing no run_ids
# Loads the table with the specified name for all runs in the given
# experiment and joins them together
import mlflow
table_dict = {
"inputs": ["What is MLflow?", "What is Databricks?"],
"outputs": ["MLflow is ...", "Databricks is ..."],
"toxicity": [0.0, 0.0],
}
with mlflow.start_run():
# Log the dictionary as a table
mlflow.log_table(data=table_dict, artifact_file="qabot_eval_results.json")
loaded_table = mlflow.load_table(
"qabot_eval_results.json",
# Append the run ID and the parent run ID to the table
extra_columns=["run_id"],
)
mlflow.log_artifact
Python Library Documentation: function log_artifact in module mlflow.tracking.fluent
log_artifact(local_path: str, artifact_path: str | None = None, run_id: str | None = None) -> None
Log a local file or directory as an artifact of the currently active run. If no run is
active, this method will create a new active run.
Args:
local_path: Path to the file to write.
artifact_path: If provided, the directory in ``artifact_uri`` to write to.
run_id: If specified, log the artifact to the specified run. If not specified, log the
artifact to the currently active run.
.. code-block:: python
:test:
:caption: Example
import tempfile
from pathlib import Path
import mlflow
# Create a features.txt artifact file
features = "rooms, zipcode, median_price, school_rating, transport"
with tempfile.TemporaryDirectory() as tmp_dir:
path = Path(tmp_dir, "features.txt")
path.write_text(features)
# With artifact_path=None write features.txt under
# root artifact_uri/artifacts directory
with mlflow.start_run():
mlflow.log_artifact(path)
mlflow.log_artifacts
Python Library Documentation: function log_artifacts in module mlflow.tracking.fluent
log_artifacts(local_dir: str, artifact_path: str | None = None, run_id: str | None = None) -> None
Log all the contents of a local directory as artifacts of the run. If no run is active,
this method will create a new active run.
Args:
local_dir: Path to the directory of files to write.
artifact_path: If provided, the directory in ``artifact_uri`` to write to.
run_id: If specified, log the artifacts to the specified run. If not specified, log the
artifacts to the currently active run.
.. code-block:: python
:test:
:caption: Example
import json
import tempfile
from pathlib import Path
import mlflow
# Create some files to preserve as artifacts
features = "rooms, zipcode, median_price, school_rating, transport"
data = {"state": "TX", "Available": 25, "Type": "Detached"}
with tempfile.TemporaryDirectory() as tmp_dir:
tmp_dir = Path(tmp_dir)
with (tmp_dir / "data.json").open("w") as f:
json.dump(data, f, indent=2)
with (tmp_dir / "features.json").open("w") as f:
f.write(features)
# Write all files in `tmp_dir` to root artifact_uri/states
with mlflow.start_run():
mlflow.log_artifacts(tmp_dir, artifact_path="states")
mlflow.log_assessment
Python Library Documentation: function log_assessment in module mlflow.tracing.assessment
log_assessment(trace_id: str, assessment: mlflow.entities.assessment.Assessment) -> mlflow.entities.assessment.Assessment
Logs an assessment to a Trace. The assessment can be an expectation or a feedback.
- Expectation: A label that represents the expected value for a particular operation.
For example, an expected answer for a user question from a chatbot.
- Feedback: A label that represents the feedback on the quality of the operation.
Feedback can come from different sources, such as human judges, heuristic scorers,
or LLM-as-a-Judge.
The following code annotates a trace with a feedback provided by LLM-as-a-Judge.
.. code-block:: python
import mlflow
from mlflow.entities import Feedback
feedback = Feedback(
name="faithfulness",
value=0.9,
rationale="The model is faithful to the input.",
metadata={"model": "gpt-4o-mini"},
)
mlflow.log_assessment(trace_id="1234", assessment=feedback)
The following code annotates a trace with human-provided ground truth with source information.
When the source is not provided, the default source is set to "default" with type "HUMAN"
.. code-block:: python
import mlflow
from mlflow.entities import AssessmentSource, AssessmentSourceType, Expectation
# Specify the annotator information as a source.
source = AssessmentSource(
source_type=AssessmentSourceType.HUMAN,
source_id="john@example.com",
)
expectation = Expectation(
name="expected_answer",
value=42,
source=source,
)
mlflow.log_assessment(trace_id="1234", assessment=expectation)
The expectation value can be any JSON-serializable value. For example, you may
record the full LLM message as the expectation value.
.. code-block:: python
import mlflow
from mlflow.entities.assessment import Expectation
expectation = Expectation(
name="expected_message",
# Full LLM message including expected tool calls
value={
"role": "assistant",
"content": "The answer is 42.",
"tool_calls": [
{
"id": "1234",
"type": "function",
"function": {"name": "add", "arguments": "40 + 2"},
}
],
},
)
mlflow.log_assessment(trace_id="1234", assessment=expectation)
You can also log an error information during the feedback generation process. To do so,
provide an instance of :py:class:`~mlflow.entities.AssessmentError` to the `error`
parameter, and leave the `value` parameter as `None`.
.. code-block:: python
import mlflow
from mlflow.entities import AssessmentError, Feedback
error = AssessmentError(
error_code="RATE_LIMIT_EXCEEDED",
error_message="Rate limit for the judge exceeded.",
)
feedback = Feedback(
trace_id="1234",
name="faithfulness",
error=error,
)
mlflow.log_assessment(trace_id="1234", assessment=feedback)
mlflow.log_dict
Python Library Documentation: function log_dict in module mlflow.tracking.fluent
log_dict(dictionary: dict[str, typing.Any], artifact_file: str, run_id: str | None = None) -> None
Log a JSON/YAML-serializable object (e.g. `dict`) as an artifact. The serialization
format (JSON or YAML) is automatically inferred from the extension of `artifact_file`.
If the file extension doesn't exist or match any of [".json", ".yml", ".yaml"],
JSON format is used.
Args:
dictionary: Dictionary to log.
artifact_file: The run-relative artifact file path in posixpath format to which
the dictionary is saved (e.g. "dir/data.json").
run_id: If specified, log the dictionary to the specified run. If not specified, log the
dictionary to the currently active run.
.. code-block:: python
:test:
:caption: Example
import mlflow
dictionary = {"k": "v"}
with mlflow.start_run():
# Log a dictionary as a JSON file under the run's root artifact directory
mlflow.log_dict(dictionary, "data.json")
# Log a dictionary as a YAML file in a subdirectory of the run's root artifact directory
mlflow.log_dict(dictionary, "dir/data.yml")
# If the file extension doesn't exist or match any of [".json", ".yaml", ".yml"],
# JSON format is used.
mlflow.log_dict(dictionary, "data")
mlflow.log_dict(dictionary, "data.txt")
mlflow.log_expectation
Python Library Documentation: function log_expectation in module mlflow.tracing.assessment
log_expectation(*, trace_id: str, name: str, value: Any, source: mlflow.entities.assessment_source.AssessmentSource | None = None, metadata: dict[str, typing.Any] | None = None, span_id: str | None = None) -> mlflow.entities.assessment.Assessment
Logs an expectation (e.g. ground truth label) to a Trace. This API only takes keyword arguments.
Args:
trace_id: The ID of the trace.
name: The name of the expectation assessment e.g., "expected_answer
value: The value of the expectation. It can be any JSON-serializable value.
source: The source of the expectation assessment. Must be an instance of
:py:class:`~mlflow.entities.AssessmentSource`. If not provided,
default to HUMAN source type.
metadata: Additional metadata for the expectation.
span_id: The ID of the span associated with the expectation, if it needs be
associated with a specific span in the trace.
Returns:
:py:class:`~mlflow.entities.Assessment`: The created expectation assessment.
Examples:
.. code-block:: python
import mlflow
from mlflow.entities import AssessmentSource, AssessmentSourceType
# Log simple expected answer
expectation = mlflow.log_expectation(
trace_id="tr-1234567890abcdef",
name="expected_answer",
value="The capital of France is Paris.",
source=AssessmentSource(
source_type=AssessmentSourceType.HUMAN, source_id="annotator@company.com"
),
metadata={"question_type": "factual", "difficulty": "easy"},
)
# Log expected classification label
mlflow.log_expectation(
trace_id="tr-1234567890abcdef",
name="expected_category",
value="positive",
source=AssessmentSource(
source_type=AssessmentSourceType.HUMAN, source_id="data_labeler_001"
),
metadata={"labeling_session": "batch_01", "confidence": 0.95},
)
mlflow.log_feedback
Python Library Documentation: function log_feedback in module mlflow.tracing.assessment
log_feedback(*, trace_id: str, name: str = 'feedback', value: float | int | str | bool | dict[str, float | int | str | bool] | list[float | int | str | bool] | None = None, source: mlflow.entities.assessment_source.AssessmentSource | None = None, error: Exception | mlflow.entities.assessment_error.AssessmentError | None = None, rationale: str | None = None, metadata: dict[str, typing.Any] | None = None, span_id: str | None = None) -> mlflow.entities.assessment.Assessment
Logs feedback to a Trace. This API only takes keyword arguments.
Args:
trace_id: The ID of the trace.
name: The name of the feedback assessment e.g., "faithfulness". Defaults to
"feedback" if not provided.
value: The value of the feedback. Can be ``None``, or one of the following types:
- float
- int
- str
- bool
- list of values of the same types as above
- dict with string keys and values of the same types as above
source: The source of the feedback assessment. Must be an instance of
:py:class:`~mlflow.entities.AssessmentSource`. If not provided, defaults to
CODE source type
error: An error object representing any issues encountered while computing the
feedback, e.g., a timeout error from an LLM judge. Accepts an exception
object, or an :py:class:`~mlflow.entities.AssessmentError` object. Either
this or `value` must be provided.
rationale: The rationale / justification for the feedback.
metadata: Additional metadata for the feedback.
span_id: The ID of the span associated with the feedback, if it needs be
associated with a specific span in the trace.
Returns:
:py:class:`~mlflow.entities.Assessment`: The created feedback assessment.
Examples:
.. code-block:: python
import mlflow
from mlflow.entities import AssessmentSource, AssessmentSourceType
# Log simple feedback score
feedback = mlflow.log_feedback(
trace_id="tr-1234567890abcdef",
name="relevance",
value=0.9,
source=AssessmentSource(
source_type=AssessmentSourceType.LLM_JUDGE, source_id="gpt-4"
),
rationale="Response directly addresses the user's question",
)
# Log detailed feedback with structured data
mlflow.log_feedback(
trace_id="tr-1234567890abcdef",
name="quality_metrics",
value={"accuracy": 0.95, "completeness": 0.88, "clarity": 0.92, "overall": 0.92},
source=AssessmentSource(
source_type=AssessmentSourceType.HUMAN, source_id="expert_evaluator"
),
rationale="High accuracy and clarity, slightly incomplete coverage",
)
mlflow.log_figure
Python Library Documentation: function log_figure in module mlflow.tracking.fluent
log_figure(figure: Union[ForwardRef('matplotlib.figure.Figure'), ForwardRef('plotly.graph_objects.Figure')], artifact_file: str, *, save_kwargs: dict[str, typing.Any] | None = None) -> None
Log a figure as an artifact. The following figure objects are supported:
- `matplotlib.figure.Figure`_
- `plotly.graph_objects.Figure`_
.. _matplotlib.figure.Figure:
https://matplotlib.org/api/_as_gen/matplotlib.figure.Figure.html
.. _plotly.graph_objects.Figure:
https://plotly.com/python-api-reference/generated/plotly.graph_objects.Figure.html
Args:
figure: Figure to log.
artifact_file: The run-relative artifact file path in posixpath format to which
the figure is saved (e.g. "dir/file.png").
save_kwargs: Additional keyword arguments passed to the method that saves the figure.
.. code-block:: python
:test:
:caption: Matplotlib Example
import mlflow
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([0, 1], [2, 3])
with mlflow.start_run():
mlflow.log_figure(fig, "figure.png")
.. code-block:: python
:test:
:caption: Plotly Example
import mlflow
from plotly import graph_objects as go
fig = go.Figure(go.Scatter(x=[0, 1], y=[2, 3]))
with mlflow.start_run():
mlflow.log_figure(fig, "figure.html")
mlflow.log_image
Python Library Documentation: function log_image in module mlflow.tracking.fluent
log_image(image: Union[ForwardRef('numpy.ndarray'), ForwardRef('PIL.Image.Image'), ForwardRef('mlflow.Image')], artifact_file: str | None = None, key: str | None = None, step: int | None = None, timestamp: int | None = None, synchronous: bool | None = False) -> None
Logs an image in MLflow, supporting two use cases:
1. Time-stepped image logging:
Ideal for tracking changes or progressions through iterative processes (e.g.,
during model training phases).
- Usage: :code:`log_image(image, key=key, step=step, timestamp=timestamp)`
2. Artifact file image logging:
Best suited for static image logging where the image is saved directly as a file
artifact.
- Usage: :code:`log_image(image, artifact_file)`
The following image formats are supported:
- `numpy.ndarray`_
- `PIL.Image.Image`_
.. _numpy.ndarray:
https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html
.. _PIL.Image.Image:
https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image
- :class:`mlflow.Image`: An MLflow wrapper around PIL image for convenient image logging.
Numpy array support
- data types:
- bool (useful for logging image masks)
- integer [0, 255]
- unsigned integer [0, 255]
- float [0.0, 1.0]
.. warning::
- Out-of-range integer values will raise ValueError.
- Out-of-range float values will auto-scale with min/max and warn.
- shape (H: height, W: width):
- H x W (Grayscale)
- H x W x 1 (Grayscale)
- H x W x 3 (an RGB channel order is assumed)
- H x W x 4 (an RGBA channel order is assumed)
Args:
image: The image object to be logged.
artifact_file: Specifies the path, in POSIX format, where the image
will be stored as an artifact relative to the run's root directory (for
example, "dir/image.png"). This parameter is kept for backward compatibility
and should not be used together with `key`, `step`, or `timestamp`.
key: Image name for time-stepped image logging. This string may only contain
alphanumerics, underscores (_), dashes (-), periods (.), spaces ( ), and
slashes (/).
step: Integer training step (iteration) at which the image was saved.
Defaults to 0.
timestamp: Time when this image was saved. Defaults to the current system time.
synchronous: *Experimental* If True, blocks until the image is logged successfully.
.. code-block:: python
:caption: Time-stepped image logging numpy example
import mlflow
import numpy as np
image = np.random.randint(0, 256, size=(100, 100, 3), dtype=np.uint8)
with mlflow.start_run():
mlflow.log_image(image, key="dogs", step=3)
.. code-block:: python
:caption: Time-stepped image logging pillow example
import mlflow
from PIL import Image
image = Image.new("RGB", (100, 100))
with mlflow.start_run():
mlflow.log_image(image, key="dogs", step=3)
.. code-block:: python
:caption: Time-stepped image logging with mlflow.Image example
import mlflow
from PIL import Image
# If you have a preexisting saved image
Image.new("RGB", (100, 100)).save("image.png")
image = mlflow.Image("image.png")
with mlflow.start_run() as run:
mlflow.log_image(run.info.run_id, image, key="dogs", step=3)
.. code-block:: python
:caption: Legacy artifact file image logging numpy example
import mlflow
import numpy as np
image = np.random.randint(0, 256, size=(100, 100, 3), dtype=np.uint8)
with mlflow.start_run():
mlflow.log_image(image, "image.png")
.. code-block:: python
:caption: Legacy artifact file image logging pillow example
import mlflow
from PIL import Image
image = Image.new("RGB", (100, 100))
with mlflow.start_run():
mlflow.log_image(image, "image.png")
mlflow.log_input
Python Library Documentation: function log_input in module mlflow.tracking.fluent
log_input(dataset: Optional[ForwardRef('Dataset')] = None, context: str | None = None, tags: dict[str, str] | None = None, model: mlflow.entities.logged_model_input.LoggedModelInput | None = None) -> None
Log a dataset used in the current run.
Args:
dataset: :py:class:`mlflow.data.dataset.Dataset` object to be logged.
context: Context in which the dataset is used. For example: "training", "testing".
This will be set as an input tag with key `mlflow.data.context`.
tags: Tags to be associated with the dataset. Dictionary of tag_key -> tag_value.
model: A :py:class:`mlflow.entities.LoggedModelInput` instance to log as input to
the run.
.. code-block:: python
:test:
:caption: Example
import numpy as np
import mlflow
array = np.asarray([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
dataset = mlflow.data.from_numpy(array, source="data.csv")
# Log an input dataset used for training
with mlflow.start_run():
mlflow.log_input(dataset, context="training")
mlflow.log_inputs
Python Library Documentation: function log_inputs in module mlflow.tracking.fluent
log_inputs(datasets: list[typing.Optional[ForwardRef('Dataset')]] | None = None, contexts: list[str | None] | None = None, tags_list: list[dict[str, str] | None] | None = None, models: list[mlflow.entities.logged_model_input.LoggedModelInput | None] | None = None) -> None
Log a batch of datasets used in the current run.
The lists of `datasets`, `contexts`, `tags_list` must have the same length.
The entries in these lists can be ``None``, which represents empty value to the
corresponding input.
Args:
datasets: List of :py:class:`mlflow.data.dataset.Dataset` object to be logged.
contexts: List of context in which the dataset is used. For example: "training", "testing".
This will be set as an input tag with key `mlflow.data.context`.
tags_list: List of tags to be associated with the dataset. Dictionary of
tag_key -> tag_value.
models: List of :py:class:`mlflow.entities.LoggedModelInput` instance to log as input
to the run. Currently only Databricks managed MLflow supports this argument.
.. code-block:: python
:test:
:caption: Example
import numpy as np
import mlflow
array = np.asarray([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
dataset = mlflow.data.from_numpy(array, source="data.csv")
array2 = np.asarray([[-1, 2, 3], [-4, 5, 6]])
dataset2 = mlflow.data.from_numpy(array2, source="data2.csv")
# Log 2 input datasets used for training and test,
# the training dataset has no tag.
# the test dataset has tags `{"my_tag": "tag_value"}`.
with mlflow.start_run():
mlflow.log_inputs(
[dataset, dataset2],
contexts=["training", "test"],
tags_list=[None, {"my_tag": "tag_value"}],
models=None,
)
mlflow.log_issue
Python Library Documentation: function log_issue in module mlflow.tracing.assessment
log_issue(*, trace_id: str, issue_id: str, issue_name: str | None = None, source: mlflow.entities.assessment_source.AssessmentSource | None = None, run_id: str | None = None, rationale: str | None = None, metadata: dict[str, str] | None = None, span_id: str | None = None) -> mlflow.entities.assessment.Assessment
Logs an issue reference to a Trace. This links a trace to a discovered issue.
This API only takes keyword arguments.
Args:
trace_id: The ID of the trace.
issue_id: The ID of the issue to reference.
issue_name: The name of the issue. If not provided, the issue name will be fetched
using the issue ID.
source: The source represents how this issue was detected on the trace, for example,
human review or automatic AI scan. Must be an instance of
:py:class:`~mlflow.entities.AssessmentSource`. If not provided, defaults to
LLM_JUDGE source type.
run_id: The ID of the run that detect the issue on the given trace.
rationale: The rationale / justification for the issue reference.
metadata: Additional metadata for the issue reference.
span_id: The ID of the span associated with the issue, if it needs to be
associated with a specific span in the trace.
Returns:
:py:class:`~mlflow.entities.Assessment`: The created issue reference assessment.
Examples:
.. code-block:: python
import mlflow
from mlflow.entities import AssessmentSource, AssessmentSourceType
# Log an issue reference to link a trace to a discovered issue
issue_ref = mlflow.log_issue(
trace_id="tr-1234567890abcdef",
issue_id="iss-abcdef123456",
source=AssessmentSource(
source_type=AssessmentSourceType.LLM_JUDGE, source_id="issue-discovery-agent"
),
run_id="run-123",
rationale="Response time exceeded 2 seconds threshold",
)
mlflow.log_metric
Python Library Documentation: function log_metric in module mlflow.tracking.fluent
log_metric(key: str, value: float, step: int | None = None, synchronous: bool | None = None, timestamp: int | None = None, run_id: str | None = None, model_id: str | None = None, dataset: Union[ForwardRef('Dataset'), mlflow.entities.dataset.Dataset, NoneType] = None) -> mlflow.utils.async_logging.run_operations.RunOperations | None
Log a metric under the current run. If no run is active, this method will create
a new active run.
Args:
key: Metric name. This string may only contain alphanumerics, underscores (_),
dashes (-), periods (.), spaces ( ), and slashes (/).
All backend stores will support keys up to length 250, but some may
support larger keys.
value: Metric value. Note that some special values such as +/- Infinity may be
replaced by other values depending on the store. For example, the
SQLAlchemy store replaces +/- Infinity with max / min float values.
All backend stores will support values up to length 5000, but some
may support larger values.
step: Metric step. Defaults to zero if unspecified.
synchronous: *Experimental* If True, blocks until the metric is logged
successfully. If False, logs the metric asynchronously and
returns a future representing the logging operation. If None, read from environment
variable `MLFLOW_ENABLE_ASYNC_LOGGING`, which defaults to False if not set.
timestamp: Time when this metric was calculated. Defaults to the current system time.
run_id: If specified, log the metric to the specified run. If not specified, log the metric
to the currently active run.
model_id: The ID of the model associated with the metric. If not specified, use the current
active model ID set by :py:func:`mlflow.set_active_model`. If no active model exists,
the models IDs associated with the specified or active run will be used.
dataset: The dataset associated with the metric.
Returns:
When `synchronous=True`, returns None.
When `synchronous=False`, returns `RunOperations` that represents future for
logging operation.
.. code-block:: python
:test:
:caption: Example
import mlflow
# Log a metric
with mlflow.start_run():
mlflow.log_metric("mse", 2500.00)
# Log a metric in async fashion.
with mlflow.start_run():
mlflow.log_metric("mse", 2500.00, synchronous=False)
mlflow.log_metrics
Python Library Documentation: function log_metrics in module mlflow.tracking.fluent
log_metrics(metrics: dict[str, float], step: int | None = None, synchronous: bool | None = None, run_id: str | None = None, timestamp: int | None = None, model_id: str | None = None, dataset: Union[ForwardRef('Dataset'), mlflow.entities.dataset.Dataset, NoneType] = None) -> mlflow.utils.async_logging.run_operations.RunOperations | None
Log multiple metrics for the current run. If no run is active, this method will create a new
active run.
Args:
metrics: Dictionary of metric_name: String -> value: Float. Note that some special
values such as +/- Infinity may be replaced by other values depending on
the store. For example, sql based store may replace +/- Infinity with
max / min float values.
step: A single integer step at which to log the specified
Metrics. If unspecified, each metric is logged at step zero.
synchronous: *Experimental* If True, blocks until the metrics are logged
successfully. If False, logs the metrics asynchronously and
returns a future representing the logging operation. If None, read from environment
variable `MLFLOW_ENABLE_ASYNC_LOGGING`, which defaults to False if not set.
run_id: Run ID. If specified, log metrics to the specified run. If not specified, log
metrics to the currently active run.
timestamp: Time when these metrics were calculated. Defaults to the current system time.
model_id: The ID of the model associated with the metric. If not specified, use the current
active model ID set by :py:func:`mlflow.set_active_model`. If no active model
exists, the models IDs associated with the specified or active run will be used.
dataset: The dataset associated with the metrics.
Returns:
When `synchronous=True`, returns None. When `synchronous=False`, returns an
:py:class:`mlflow.utils.async_logging.run_operations.RunOperations` instance that
represents future for logging operation.
.. code-block:: python
:test:
:caption: Example
import mlflow
metrics = {"mse": 2500.00, "rmse": 50.00}
# Log a batch of metrics
with mlflow.start_run():
mlflow.log_metrics(metrics)
# Log a batch of metrics in async fashion.
with mlflow.start_run():
mlflow.log_metrics(metrics, synchronous=False)
mlflow.log_model_params
Python Library Documentation: function log_model_params in module mlflow.tracking.fluent
log_model_params(params: dict[str, str], model_id: str | None = None) -> None
Log params to the specified logged model.
Args:
params: Params to log on the model.
model_id: ID of the model. If not specified, use the current active model ID.
Returns:
None
Example:
.. code-block:: python
:test:
import mlflow
class DummyModel(mlflow.pyfunc.PythonModel):
def predict(self, context, model_input: list[str]) -> list[str]:
return model_input
model_info = mlflow.pyfunc.log_model(name="model", python_model=DummyModel())
mlflow.log_model_params(params={"param": "value"}, model_id=model_info.model_id)
mlflow.log_outputs
Python Library Documentation: function log_outputs in module mlflow.tracking.fluent
log_outputs(models: list[mlflow.entities.logged_model_output.LoggedModelOutput] | None = None)
Log outputs, such as models, to the active run. If there is no active run, a new run will be
created.
Args:
models: List of :py:class:`mlflow.entities.LoggedModelOutput` instances to log
as outputs to the run.
Returns:
None.
mlflow.log_param
Python Library Documentation: function log_param in module mlflow.tracking.fluent
log_param(key: str, value: Any, synchronous: bool | None = None) -> Any
Log a parameter (e.g. model hyperparameter) under the current run. If no run is active,
this method will create a new active run.
Args:
key: Parameter name. This string may only contain alphanumerics, underscores (_), dashes
(-), periods (.), spaces ( ), and slashes (/). All backend stores support keys up to
length 250, but some may support larger keys.
value: Parameter value, but will be string-ified if not. All built-in backend stores support
values up to length 6000, but some may support larger values.
synchronous: *Experimental* If True, blocks until the parameter is logged successfully. If
False, logs the parameter asynchronously and returns a future representing the logging
operation. If None, read from environment variable `MLFLOW_ENABLE_ASYNC_LOGGING`,
which defaults to False if not set.
Returns:
When `synchronous=True`, returns parameter value. When `synchronous=False`, returns an
:py:class:`mlflow.utils.async_logging.run_operations.RunOperations` instance that represents
future for logging operation.
.. code-block:: python
:test:
:caption: Example
import mlflow
with mlflow.start_run():
value = mlflow.log_param("learning_rate", 0.01)
assert value == 0.01
value = mlflow.log_param("learning_rate", 0.02, synchronous=False)
mlflow.log_params
Python Library Documentation: function log_params in module mlflow.tracking.fluent
log_params(params: dict[str, typing.Any], synchronous: bool | None = None, run_id: str | None = None) -> mlflow.utils.async_logging.run_operations.RunOperations | None
Log a batch of params for the current run. If no run is active, this method will create a
new active run.
Args:
params: Dictionary of param_name: String -> value: (String, but will be string-ified if
not)
synchronous: *Experimental* If True, blocks until the parameters are logged
successfully. If False, logs the parameters asynchronously and
returns a future representing the logging operation. If None, read from environment
variable `MLFLOW_ENABLE_ASYNC_LOGGING`, which defaults to False if not set.
run_id: Run ID. If specified, log params to the specified run. If not specified, log
params to the currently active run.
Returns:
When `synchronous=True`, returns None. When `synchronous=False`, returns an
:py:class:`mlflow.utils.async_logging.run_operations.RunOperations` instance that
represents future for logging operation.
.. code-block:: python
:test:
:caption: Example
import mlflow
params = {"learning_rate": 0.01, "n_estimators": 10}
# Log a batch of parameters
with mlflow.start_run():
mlflow.log_params(params)
# Log a batch of parameters in async fashion.
with mlflow.start_run():
mlflow.log_params(params, synchronous=False)
mlflow.log_stream
Python Library Documentation: function log_stream in module mlflow.tracking.fluent
log_stream(stream: io.BufferedIOBase | io.RawIOBase, artifact_file: str, run_id: str | None = None) -> None
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Log a binary file-like object (e.g., ``io.BytesIO``) as an artifact.
Args:
stream: A binary file-like object supporting ``.read()`` method (e.g., ``io.BytesIO``).
artifact_file: The run-relative artifact file path in posixpath format to which
the stream content is saved (e.g. "dir/file.bin").
run_id: If specified, log the artifact to the specified run. If not specified, log the
artifact to the currently active run.
.. code-block:: python
:test:
:caption: Example
import io
import mlflow
with mlflow.start_run():
# Log a BytesIO stream
bytes_stream = io.BytesIO(b"binary content")
mlflow.log_stream(bytes_stream, "binary_file.bin")
mlflow.log_table
Python Library Documentation: function log_table in module mlflow.tracking.fluent
log_table(data: Union[dict[str, Any], ForwardRef('pandas.DataFrame')], artifact_file: str, run_id: str | None = None) -> None
Log a table to MLflow Tracking as a JSON artifact. If the artifact_file already exists
in the run, the data would be appended to the existing artifact_file.
Args:
data: Dictionary or pandas.DataFrame to log.
artifact_file: The run-relative artifact file path in posixpath format to which
the table is saved (e.g. "dir/file.json").
run_id: If specified, log the table to the specified run. If not specified, log the
table to the currently active run.
.. code-block:: python
:test:
:caption: Dictionary Example
import mlflow
table_dict = {
"inputs": ["What is MLflow?", "What is Databricks?"],
"outputs": ["MLflow is ...", "Databricks is ..."],
"toxicity": [0.0, 0.0],
}
with mlflow.start_run():
# Log the dictionary as a table
mlflow.log_table(data=table_dict, artifact_file="qabot_eval_results.json")
.. code-block:: python
:test:
:caption: Pandas DF Example
import mlflow
import pandas as pd
table_dict = {
"inputs": ["What is MLflow?", "What is Databricks?"],
"outputs": ["MLflow is ...", "Databricks is ..."],
"toxicity": [0.0, 0.0],
}
df = pd.DataFrame.from_dict(table_dict)
with mlflow.start_run():
# Log the df as a table
mlflow.log_table(data=df, artifact_file="qabot_eval_results.json")
mlflow.log_text
Python Library Documentation: function log_text in module mlflow.tracking.fluent
log_text(text: str, artifact_file: str, run_id: str | None = None) -> None
Log text as an artifact.
Args:
text: String containing text to log.
artifact_file: The run-relative artifact file path in posixpath format to which
the text is saved (e.g. "dir/file.txt").
run_id: If specified, log the artifact to the specified run. If not specified, log the
artifact to the currently active run.
.. code-block:: python
:test:
:caption: Example
import mlflow
with mlflow.start_run():
# Log text to a file under the run's root artifact directory
mlflow.log_text("text1", "file1.txt")
# Log text in a subdirectory of the run's root artifact directory
mlflow.log_text("text2", "dir/file2.txt")
# Log HTML text
mlflow.log_text("<h1>header</h1>", "index.html")
mlflow.log_trace
Python Library Documentation: function log_trace in module mlflow.tracing.fluent
log_trace(name: 'str' = 'Task', request: 'Any | None' = None, response: 'Any | None' = None, intermediate_outputs: 'dict[str, Any] | None' = None, attributes: 'dict[str, Any] | None' = None, tags: 'dict[str, str] | None' = None, start_time_ms: 'int | None' = None, execution_time_ms: 'int | None' = None) -> 'str'
.. Warning:: ``mlflow.tracing.fluent.log_trace`` is deprecated since 3.6.0. This method will be removed in a future release.
Create a trace with a single root span.
This API is useful when you want to log an arbitrary (request, response) pair
without structured OpenTelemetry spans. The trace is linked to the active experiment.
Args:
name: The name of the trace (and the root span). Default to "Task".
request: Input data for the entire trace. This is also set on the root span of the trace.
response: Output data for the entire trace. This is also set on the root span of the trace.
intermediate_outputs: A dictionary of intermediate outputs produced by the model or agent
while handling the request. Keys are the names of the outputs,
and values are the outputs themselves. Values must be JSON-serializable.
attributes: A dictionary of attributes to set on the root span of the trace.
tags: A dictionary of tags to set on the trace.
start_time_ms: The start time of the trace in milliseconds since the UNIX epoch.
When not specified, current time is used for start and end time of the trace.
execution_time_ms: The execution time of the trace in milliseconds since the UNIX epoch.
Returns:
The ID of the logged trace.
Example:
.. code-block:: python
:test:
import time
import mlflow
trace_id = mlflow.log_trace(
request="Does mlflow support tracing?",
response="Yes",
intermediate_outputs={
"retrieved_documents": ["mlflow documentation"],
"system_prompt": ["answer the question with yes or no"],
},
start_time_ms=int(time.time() * 1000),
execution_time_ms=5129,
)
trace = mlflow.get_trace(trace_id, flush=True)
print(trace.data.intermediate_outputs)
mlflow.login
Python Library Documentation: function login in module mlflow.utils.credentials
login(backend: str = 'databricks', interactive: bool = True) -> None
Configure MLflow server authentication and connect MLflow to tracking server.
This method provides a simple way to connect MLflow to its tracking server. Currently only
Databricks tracking server is supported. Users will be prompted to enter the credentials if no
existing Databricks profile is found, and the credentials will be saved to `~/.databrickscfg`.
Args:
backend: string, the backend of the tracking server. Currently only "databricks" is
supported.
interactive: bool, controls request for user input on missing credentials. If true, user
input will be requested if no credentials are found, otherwise an exception will be
raised if no credentials are found.
.. code-block:: python
:caption: Example
import mlflow
mlflow.login()
with mlflow.start_run():
mlflow.log_param("p", 0)
mlflow.metrics
Python Library Documentation: package mlflow.metrics in mlflow
NAME
mlflow.metrics
PACKAGE CONTENTS
base
genai (package)
metric_definitions
CLASSES
builtins.object
mlflow.metrics.base.MetricValue
mlflow.models.evaluation.base.EvaluationMetric
class EvaluationMetric(builtins.object)
| EvaluationMetric(eval_fn, name, greater_is_better, long_name=None, version=None, metric_details=None, metric_metadata=None, genai_metric_args=None)
|
| An evaluation metric.
|
| Args:
| eval_fn: A function that computes the metric with the following signature:
|
| .. code-block:: python
|
| def eval_fn(
| predictions: pandas.Series,
| targets: pandas.Series,
| metrics: Dict[str, MetricValue],
| **kwargs,
| ) -> Union[float, MetricValue]:
| """
| Args:
| predictions: A pandas Series containing the predictions made by the model.
| targets: (Optional) A pandas Series containing the corresponding labels
| for the predictions made on that input.
| metrics: (Optional) A dictionary containing the metrics calculated by the
| default evaluator. The keys are the names of the metrics and the values
| are the metric values. To access the MetricValue for the metrics
| calculated by the system, make sure to specify the type hint for this
| parameter as Dict[str, MetricValue]. Refer to the DefaultEvaluator
| behavior section for what metrics will be returned based on the type of
| model (i.e. classifier or regressor).
| kwargs: Includes a list of args that are used to compute the metric. These
| args could be information coming from input data, model outputs,
| other metrics, or parameters specified in the `evaluator_config`
| argument of the `mlflow.evaluate` API.
|
| Returns: MetricValue with per-row scores, per-row justifications, and aggregate
| results.
| """
| ...
|
| name: The name of the metric.
| greater_is_better: Whether a greater value of the metric is better.
| long_name: (Optional) The long name of the metric. For example,
| ``"root_mean_squared_error"`` for ``"mse"``.
| version: (Optional) The metric version. For example ``v1``.
| metric_details: (Optional) A description of the metric and how it is calculated.
| metric_metadata: (Optional) A dictionary containing metadata for the metric.
| genai_metric_args: (Optional) A dictionary containing arguments specified by users
| when calling make_genai_metric or make_genai_metric_from_prompt. Those args
| are persisted so that we can deserialize the same metric object later.
|
| Methods defined here:
|
| __init__(self, eval_fn, name, greater_is_better, long_name=None, version=None, metric_details=None, metric_metadata=None, genai_metric_args=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| __str__(self)
| Return str(self).
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class MetricValue(builtins.object)
| MetricValue(scores: list[str] | list[float] | None = None, justifications: list[str] | None = None, aggregate_results: dict[str, float] | None = None) -> None
|
| The value of a metric.
|
|
| Args:
| scores: The value of the metric per row
| justifications: The justification (if applicable) for the respective score
| aggregate_results: A dictionary mapping the name of the aggregation to its value
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, scores: list[str] | list[float] | None = None, justifications: list[str] | None = None, aggregate_results: dict[str, float] | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __post_init__(self)
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'aggregate_results': dict[str, float] | None, 'just...
|
| __dataclass_fields__ = {'aggregate_results': Field(name='aggregate_res...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('scores', 'justifications', 'aggregate_results')
|
| aggregate_results = None
|
| justifications = None
|
| scores = None
FUNCTIONS
ari_grade_level() -> mlflow.models.evaluation.base.EvaluationMetric
.. Warning:: ``mlflow.metrics.ari_grade_level`` is deprecated since 3.4.0. Use the new GenAI evaluation functionality instead. See https://mlflow.org/docs/latest/genai/eval-monitor/legacy-llm-evaluation/ for the migration guide.
This function will create a metric for calculating `automated readability index`_ using
`textstat`_.
This metric outputs a number that approximates the grade level needed to comprehend the text,
which will likely range from around 0 to 15 (although it is not limited to this range).
Aggregations calculated for this metric:
- mean
.. _automated readability index: https://en.wikipedia.org/wiki/Automated_readability_index
.. _textstat: https://pypi.org/project/textstat/
bleu() -> mlflow.models.evaluation.base.EvaluationMetric
.. Warning:: ``mlflow.metrics.bleu`` is deprecated since 3.4.0. Use the new GenAI evaluation functionality instead. See https://mlflow.org/docs/latest/genai/eval-monitor/legacy-llm-evaluation/ for the migration guide.
This function will create a metric for evaluating `bleu`_.
The BLEU scores range from 0 to 1, with higher scores indicating greater similarity to
reference texts. BLEU considers n-gram precision and brevity penalty. While adding more
references can boost the score, perfect scores are rare and not essential for effective
evaluation.
Aggregations calculated for this metric:
- mean
- variance
- p90
.. _bleu: https://huggingface.co/spaces/evaluate-metric/bleu
exact_match() -> mlflow.models.evaluation.base.EvaluationMetric
.. Warning:: ``mlflow.metrics.exact_match`` is deprecated since 3.4.0. Use the new GenAI evaluation functionality instead. See https://mlflow.org/docs/latest/genai/eval-monitor/legacy-llm-evaluation/ for the migration guide.
This function will create a metric for calculating `accuracy`_ using sklearn.
This metric only computes an aggregate score which ranges from 0 to 1.
.. _accuracy: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.accuracy_score.html
f1_score() -> mlflow.models.evaluation.base.EvaluationMetric
This function will create a metric for evaluating `f1_score`_ for binary classification.
This metric computes an aggregate score between 0 and 1 for the F1 score (F-measure) of a
classification task. F1 score is defined as 2 * (precision * recall) / (precision + recall).
.. _f1_score: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html
flesch_kincaid_grade_level() -> mlflow.models.evaluation.base.EvaluationMetric
.. Warning:: ``mlflow.metrics.flesch_kincaid_grade_level`` is deprecated since 3.4.0. Use the new GenAI evaluation functionality instead. See https://mlflow.org/docs/latest/genai/eval-monitor/legacy-llm-evaluation/ for the migration guide.
This function will create a metric for calculating `flesch kincaid grade level`_ using
`textstat`_.
This metric outputs a number that approximates the grade level needed to comprehend the text,
which will likely range from around 0 to 15 (although it is not limited to this range).
Aggregations calculated for this metric:
- mean
.. _flesch kincaid grade level:
https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests#Flesch%E2%80%93Kincaid_grade_level
.. _textstat: https://pypi.org/project/textstat/
latency() -> mlflow.models.evaluation.base.EvaluationMetric
.. Warning:: ``mlflow.metrics.latency`` is deprecated since 3.4.0. Use the new GenAI evaluation functionality instead. See https://mlflow.org/docs/latest/genai/eval-monitor/legacy-llm-evaluation/ for the migration guide.
This function will create a metric for calculating latency. Latency is determined by the time
it takes to generate a prediction for a given input. Note that computing latency requires
each row to be predicted sequentially, which will likely slow down the evaluation process.
mae() -> mlflow.models.evaluation.base.EvaluationMetric
This function will create a metric for evaluating `mae`_.
This metric computes an aggregate score for the mean absolute error for regression.
.. _mae: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_absolute_error.html
make_metric(*, eval_fn, greater_is_better, name=None, long_name=None, version=None, metric_details=None, metric_metadata=None, genai_metric_args=None)
A factory function to create an :py:class:`EvaluationMetric` object.
Args:
eval_fn: A function that computes the metric with the following signature:
.. code-block:: python
def eval_fn(
predictions: pandas.Series,
targets: pandas.Series,
metrics: Dict[str, MetricValue],
**kwargs,
) -> Union[float, MetricValue]:
"""
Args:
predictions: A pandas Series containing the predictions made by the model.
targets: (Optional) A pandas Series containing the corresponding labels
for the predictions made on that input.
metrics: (Optional) A dictionary containing the metrics calculated by the
default evaluator. The keys are the names of the metrics and the values
are the metric values. To access the MetricValue for the metrics
calculated by the system, make sure to specify the type hint for this
parameter as Dict[str, MetricValue]. Refer to the DefaultEvaluator
behavior section for what metrics will be returned based on the type of
model (i.e. classifier or regressor). kwargs: Includes a list of args
that are used to compute the metric. These args could information coming
from input data, model outputs or parameters specified in the
`evaluator_config` argument of the `mlflow.evaluate` API.
kwargs: Includes a list of args that are used to compute the metric. These
args could be information coming from input data, model outputs,
other metrics, or parameters specified in the `evaluator_config`
argument of the `mlflow.evaluate` API.
Returns: MetricValue with per-row scores, per-row justifications, and aggregate
results.
"""
...
greater_is_better: Whether a greater value of the metric is better.
name: The name of the metric. This argument must be specified if ``eval_fn`` is a lambda
function or the ``eval_fn.__name__`` attribute is not available.
long_name: (Optional) The long name of the metric. For example, ``"mean_squared_error"``
for ``"mse"``.
version: (Optional) The metric version. For example ``v1``.
metric_details: (Optional) A description of the metric and how it is calculated.
metric_metadata: (Optional) A dictionary containing metadata for the metric.
genai_metric_args: (Optional) A dictionary containing arguments specified by users
when calling make_genai_metric or make_genai_metric_from_prompt. Those args
are persisted so that we can deserialize the same metric object later.
.. seealso::
- :py:class:`mlflow.models.EvaluationMetric`
- :py:func:`mlflow.evaluate`
mape() -> mlflow.models.evaluation.base.EvaluationMetric
This function will create a metric for evaluating `mape`_.
This metric computes an aggregate score for the mean absolute percentage error for regression.
.. _mape: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_absolute_percentage_error.html
max_error() -> mlflow.models.evaluation.base.EvaluationMetric
This function will create a metric for evaluating `max_error`_.
This metric computes an aggregate score for the maximum residual error for regression.
.. _max_error: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.max_error.html
mse() -> mlflow.models.evaluation.base.EvaluationMetric
This function will create a metric for evaluating `mse`_.
This metric computes an aggregate score for the mean squared error for regression.
.. _mse: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_squared_error.html
precision_score() -> mlflow.models.evaluation.base.EvaluationMetric
This function will create a metric for evaluating `precision`_ for classification.
This metric computes an aggregate score between 0 and 1 for the precision of
classification task.
.. _precision: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_score.html
r2_score() -> mlflow.models.evaluation.base.EvaluationMetric
This function will create a metric for evaluating `r2_score`_.
This metric computes an aggregate score for the coefficient of determination. R2 ranges from
negative infinity to 1, and measures the percentage of variance explained by the predictor
variables in a regression.
.. _r2_score: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.r2_score.html
recall_score() -> mlflow.models.evaluation.base.EvaluationMetric
This function will create a metric for evaluating `recall`_ for classification.
This metric computes an aggregate score between 0 and 1 for the recall of a classification task.
.. _recall: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.recall_score.html
rmse() -> mlflow.models.evaluation.base.EvaluationMetric
This function will create a metric for evaluating the square root of `mse`_.
This metric computes an aggregate score for the root mean absolute error for regression.
.. _mse: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_squared_error.html
rouge1() -> mlflow.models.evaluation.base.EvaluationMetric
.. Warning:: ``mlflow.metrics.rouge1`` is deprecated since 3.4.0. Use the new GenAI evaluation functionality instead. See https://mlflow.org/docs/latest/genai/eval-monitor/legacy-llm-evaluation/ for the migration guide.
This function will create a metric for evaluating `rouge1`_.
The score ranges from 0 to 1, where a higher score indicates higher similarity.
`rouge1`_ uses unigram based scoring to calculate similarity.
Aggregations calculated for this metric:
- mean
.. _rouge1: https://huggingface.co/spaces/evaluate-metric/rouge
rouge2() -> mlflow.models.evaluation.base.EvaluationMetric
.. Warning:: ``mlflow.metrics.rouge2`` is deprecated since 3.4.0. Use the new GenAI evaluation functionality instead. See https://mlflow.org/docs/latest/genai/eval-monitor/legacy-llm-evaluation/ for the migration guide.
This function will create a metric for evaluating `rouge2`_.
The score ranges from 0 to 1, where a higher score indicates higher similarity.
`rouge2`_ uses bigram based scoring to calculate similarity.
Aggregations calculated for this metric:
- mean
.. _rouge2: https://huggingface.co/spaces/evaluate-metric/rouge
rougeL() -> mlflow.models.evaluation.base.EvaluationMetric
.. Warning:: ``mlflow.metrics.rougeL`` is deprecated since 3.4.0. Use the new GenAI evaluation functionality instead. See https://mlflow.org/docs/latest/genai/eval-monitor/legacy-llm-evaluation/ for the migration guide.
This function will create a metric for evaluating `rougeL`_.
The score ranges from 0 to 1, where a higher score indicates higher similarity.
`rougeL`_ uses unigram based scoring to calculate similarity.
Aggregations calculated for this metric:
- mean
.. _rougeL: https://huggingface.co/spaces/evaluate-metric/rouge
rougeLsum() -> mlflow.models.evaluation.base.EvaluationMetric
.. Warning:: ``mlflow.metrics.rougeLsum`` is deprecated since 3.4.0. Use the new GenAI evaluation functionality instead. See https://mlflow.org/docs/latest/genai/eval-monitor/legacy-llm-evaluation/ for the migration guide.
This function will create a metric for evaluating `rougeLsum`_.
The score ranges from 0 to 1, where a higher score indicates higher similarity.
`rougeLsum`_ uses longest common subsequence based scoring to calculate similarity.
Aggregations calculated for this metric:
- mean
.. _rougeLsum: https://huggingface.co/spaces/evaluate-metric/rouge
token_count(encoding: str = 'cl100k_base') -> mlflow.models.evaluation.base.EvaluationMetric
.. Warning:: ``mlflow.metrics.token_count`` is deprecated since 3.4.0. Use the new GenAI evaluation functionality instead. See https://mlflow.org/docs/latest/genai/eval-monitor/legacy-llm-evaluation/ for the migration guide.
This function will create a metric for calculating token_count. Token count is calculated
using tiktoken by using the `cl100k_base` tokenizer.
Note: For air-gapped environments, you can set the TIKTOKEN_CACHE_DIR environment variable
to specify a local cache directory for tiktoken to avoid downloading the tokenizer files.
toxicity() -> mlflow.models.evaluation.base.EvaluationMetric
.. Warning:: ``mlflow.metrics.toxicity`` is deprecated since 3.4.0. Use the new GenAI evaluation functionality instead. See https://mlflow.org/docs/latest/genai/eval-monitor/legacy-llm-evaluation/ for the migration guide.
This function will create a metric for evaluating `toxicity`_ using the model
`roberta-hate-speech-dynabench-r4`_, which defines hate as "abusive speech targeting
specific group characteristics, such as ethnic origin, religion, gender, or sexual
orientation."
The score ranges from 0 to 1, where scores closer to 1 are more toxic. The default threshold
for a text to be considered "toxic" is 0.5.
Aggregations calculated for this metric:
- ratio (of toxic input texts)
.. _toxicity: https://huggingface.co/spaces/evaluate-measurement/toxicity
.. _roberta-hate-speech-dynabench-r4: https://huggingface.co/facebook/roberta-hate-speech-dynabench-r4-target
DATA
__all__ = ['EvaluationMetric', 'MetricValue', 'make_metric', 'flesch_k...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\metrics\__init__.py
mlflow.mismatch
Python Library Documentation: module mlflow.mismatch in mlflow
NAME
mlflow.mismatch
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\mismatch.py
mlflow.mistral
Python Library Documentation: package mlflow.mistral in mlflow
NAME
mlflow.mistral
PACKAGE CONTENTS
autolog
chat
DATA
FLAVOR_NAME = 'mistral'
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\mistral\__init__.py
mlflow.ml_package_versions
Python Library Documentation: module mlflow.ml_package_versions in mlflow
NAME
mlflow.ml_package_versions
DESCRIPTION
# This file was auto-generated by `flavors update`.
# Please do not edit it manually.
DATA
FLAVOR_TO_MODULE_NAME = {'ag2': 'autogen', 'agno': 'agno', 'anthropic'...
GENAI_FLAVOR_TO_MODULE_NAME = {'ag2': 'autogen', 'agno': 'agno', 'anth...
NON_GENAI_FLAVOR_TO_MODULE_NAME = {'haystack': 'haystack', 'keras': 'k...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\ml_package_versions.py
mlflow.mlflow
Python Library Documentation: package mlflow
NAME
mlflow
DESCRIPTION
The ``mlflow`` module provides a high-level "fluent" API for starting and managing MLflow runs.
For example:
.. code:: python
import mlflow
mlflow.start_run()
mlflow.log_param("my", "param")
mlflow.log_metric("score", 100)
mlflow.end_run()
You can also use the context manager syntax like this:
.. code:: python
with mlflow.start_run() as run:
mlflow.log_param("my", "param")
mlflow.log_metric("score", 100)
which automatically terminates the run at the end of the ``with`` block.
The fluent tracking API is not currently threadsafe. Any concurrent callers to the tracking API must
implement mutual exclusion manually.
For a lower level API, see the :py:mod:`mlflow.client` module.
PACKAGE CONTENTS
__main__
ag2 (package)
agent (package)
agno (package)
ai_commands (package)
anthropic (package)
artifacts (package)
assistant (package)
autogen (package)
azure (package)
bedrock (package)
catboost (package)
claude_code (package)
cli (package)
client
config (package)
crewai (package)
data (package)
db
demo (package)
deployments (package)
diffusers (package)
dspy (package)
entities (package)
environment_variables
error_classification
evaluation (package)
exceptions
experiments
gateway (package)
gemini (package)
genai (package)
groq (package)
h2o (package)
haystack (package)
johnsnowlabs (package)
keras (package)
langchain (package)
legacy_databricks_cli (package)
lightgbm (package)
litellm (package)
llama_index (package)
mcp (package)
metrics (package)
mismatch
mistral (package)
ml_package_versions
models (package)
onnx (package)
openai (package)
optuna (package)
otel (package)
paddle (package)
pmdarima (package)
projects (package)
prompt (package)
prophet (package)
protos (package)
pydantic_ai (package)
pyfunc (package)
pyspark (package)
pytest (package)
pytorch (package)
rfunc (package)
runs
sagemaker (package)
semantic_kernel (package)
sentence_transformers (package)
server (package)
shap (package)
sklearn (package)
smolagents (package)
spacy (package)
spark (package)
statsmodels (package)
store (package)
strands (package)
system_metrics (package)
telemetry (package)
tensorflow (package)
tracing (package)
tracking (package)
transformers (package)
types (package)
utils (package)
version
webhooks (package)
xgboost (package)
SUBMODULES
mlflow.ag2
mlflow.agno
mlflow.anthropic
mlflow.autogen
mlflow.bedrock
mlflow.catboost
mlflow.crewai
mlflow.diffusers
mlflow.dspy
mlflow.gemini
mlflow.groq
mlflow.h2o
mlflow.johnsnowlabs
mlflow.langchain
mlflow.lightgbm
mlflow.litellm
mlflow.llama_index
mlflow.metrics
mlflow.mistral
CLASSES
builtins.Exception(builtins.BaseException)
mlflow.exceptions.MlflowException
builtins.object
mlflow.tracking.client.MlflowClient
mlflow.tracking.multimedia.Image
mlflow.entities.logged_model.LoggedModel(mlflow.entities._mlflow_object._MlflowObject)
mlflow.tracking.fluent.ActiveModel
mlflow.entities.run.Run(mlflow.entities._mlflow_object._MlflowObject)
mlflow.tracking.fluent.ActiveRun
class ActiveModel(mlflow.entities.logged_model.LoggedModel)
| ActiveModel(logged_model: mlflow.entities.logged_model.LoggedModel, set_by_user: bool)
|
| Wrapper around :py:class:`mlflow.entities.LoggedModel` to enable using Python ``with`` syntax.
|
| Method resolution order:
| ActiveModel
| mlflow.entities.logged_model.LoggedModel
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __enter__(self)
|
| __exit__(self, exc_type, exc_val, exc_tb)
|
| __init__(self, logged_model: mlflow.entities.logged_model.LoggedModel, set_by_user: bool)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities.logged_model.LoggedModel:
|
| __repr__(self) -> str
| Return repr(self).
|
| to_dictionary(self) -> dict[str, typing.Any]
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities.logged_model.LoggedModel:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Readonly properties inherited from mlflow.entities.logged_model.LoggedModel:
|
| creation_timestamp
| Integer. Model creation timestamp (milliseconds since the Unix epoch).
|
| model_uri
| URI of the model.
|
| params
| Model parameters.
|
| source_run_id
| String. MLflow run ID that generated this model.
|
| status_message
| String. Descriptive message for error status conditions.
|
| tags
| Dictionary of tag key (string) -> tag value for this Model.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities.logged_model.LoggedModel:
|
| artifact_location
| String. Location of the model artifacts.
|
| experiment_id
| String. Experiment ID associated with this Model.
|
| last_updated_timestamp
| Integer. Timestamp of last update for this Model (milliseconds since the Unix
| epoch).
|
| metrics
| List of metrics associated with this Model.
|
| model_id
| String. Unique ID for this Model.
|
| model_type
| String. Type of the model.
|
| name
| String. Name for this Model.
|
| status
| String. Current status of this Model.
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class ActiveRun(mlflow.entities.run.Run)
| ActiveRun(run)
|
| Wrapper around :py:class:`mlflow.entities.Run` to enable using Python ``with`` syntax.
|
| Method resolution order:
| ActiveRun
| mlflow.entities.run.Run
| mlflow.entities._mlflow_object._MlflowObject
| builtins.object
|
| Methods defined here:
|
| __enter__(self)
|
| __exit__(self, exc_type, exc_val, exc_tb)
|
| __init__(self, run)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities.run.Run:
|
| to_dictionary(self) -> dict[typing.Any, typing.Any]
|
| to_proto(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities.run.Run:
|
| from_proto(proto)
|
| ----------------------------------------------------------------------
| Readonly properties inherited from mlflow.entities.run.Run:
|
| data
| The run data, including metrics, parameters, and tags.
|
| :rtype: :py:class:`mlflow.entities.RunData`
|
| info
| The run metadata, such as the run id, start time, and status.
|
| :rtype: :py:class:`mlflow.entities.RunInfo`
|
| inputs
| The run inputs, including dataset inputs.
|
| :rtype: :py:class:`mlflow.entities.RunInputs`
|
| outputs
| The run outputs, including model outputs.
|
| :rtype: :py:class:`mlflow.entities.RunOutputs`
|
| ----------------------------------------------------------------------
| Methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __iter__(self)
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Class methods inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| from_dictionary(the_dict)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from mlflow.entities._mlflow_object._MlflowObject:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class Image(builtins.object)
| Image(image: Union[ForwardRef('numpy.ndarray'), ForwardRef('PIL.Image.Image'), str, list[Any]])
|
| `mlflow.Image` is an image media object that provides a lightweight option
| for handling images in MLflow.
| The image can be a numpy array, a PIL image, or a file path to an image. The image is
| stored as a PIL image and can be logged to MLflow using `mlflow.log_image` or
| `mlflow.log_table`.
|
| Args:
| image: Image can be a numpy array, a PIL image, or a file path to an image.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| import numpy as np
| from PIL import Image
|
| # Create an image as a numpy array
| image = np.zeros((100, 100, 3), dtype=np.uint8)
| image[:, :50] = [255, 128, 0]
| # Create an Image object
| image_obj = mlflow.Image(image)
| # Convert the Image object to a list of pixel values
| pixel_values = image_obj.to_list()
|
| Methods defined here:
|
| __init__(self, image: Union[ForwardRef('numpy.ndarray'), ForwardRef('PIL.Image.Image'), str, list[Any]])
| Initialize self. See help(type(self)) for accurate signature.
|
| resize(self, size: tuple[int, int])
| Resize the image to the specified size.
|
| Args:
| size: Size to resize the image to.
|
| Returns:
| A copy of the resized image object.
|
| save(self, path: str)
| Save the image to a file.
|
| Args:
| path: File path to save the image.
|
| to_array(self)
| Convert the image to a numpy array.
|
| Returns:
| Numpy array of pixel values.
|
| to_list(self)
| Convert the image to a list of pixel values.
|
| Returns:
| List of pixel values.
|
| to_pil(self)
| Convert the image to a PIL image.
|
| Returns:
| PIL image.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class MlflowClient(builtins.object)
| MlflowClient(tracking_uri: str | None = None, registry_uri: str | None = None, workspace_store_uri: str | None = None)
|
| Client of an MLflow Tracking Server that creates and manages experiments and runs, and of an
| MLflow Registry Server that creates and manages registered models and model versions. It also
| exposes workspace CRUD via the configured workspace provider. It's a thin wrapper around:
|
| - TrackingServiceClient for tracking operations
| - WorkspaceProviderClient for workspace operations
| - ModelRegistryClient for registry operations
|
| This layered structure provides a unified API while preserving independent implementations.
|
| Methods defined here:
|
| __init__(self, tracking_uri: str | None = None, registry_uri: str | None = None, workspace_store_uri: str | None = None)
| Args:
| tracking_uri: Address of local or remote tracking server. If not provided, defaults
| to the service set by ``mlflow.tracking.set_tracking_uri``. See
| `Where Runs Get Recorded <../tracking.html#where-runs-get-recorded>`_
| for more info.
| registry_uri: Address of local or remote model registry server. If not provided,
| defaults to the service set by ``mlflow.tracking.set_registry_uri``. If
| no such service was set, defaults to the tracking uri of the client.
| workspace_store_uri: Address of the workspace provider backend. Defaults to the tracking
| URI when unspecified, but can be pointed at a dedicated workspace store.
|
| add_dataset_to_experiments(self, dataset_id: str, experiment_ids: list[str]) -> mlflow.entities.evaluation_dataset.EvaluationDataset
| Add a dataset to additional experiments.
|
| This allows reusing datasets across multiple experiments for evaluation purposes.
|
| Args:
| dataset_id: The ID of the dataset to update.
| experiment_ids: List of experiment IDs to associate with the dataset.
|
| Returns:
| The updated EvaluationDataset with new experiment associations.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Add dataset to new experiments
| dataset = client.add_dataset_to_experiments(
| dataset_id="d-abc123", experiment_ids=["1", "2", "3"]
| )
| print(f"Dataset now associated with {len(dataset.experiment_ids)} experiments")
|
| copy_model_version(self, src_model_uri, dst_name) -> mlflow.entities.model_registry.model_version.ModelVersion
| Copy a model version from one registered model to another as a new model version.
| If the destination model does not exist, it will be created.
|
| This method can also be used to migrate model versions from the Databricks workspace
| registry to Unity Catalog. During the migration, signature validation can be bypassed
| by setting the `MLFLOW_SKIP_SIGNATURE_CHECK_FOR_UC_REGISTRY_MIGRATION`environment
| variable to `True`.
|
| Args:
| src_model_uri: The model URI of the model version to copy. This must be a model
| registry URI with a `"models:/"` scheme (e.g., `"models:/iris_model@champion"`).
| dst_name: The name of the registered model to copy the model version to. If a
| registered model with this name does not exist, it will be created.
|
| Returns:
| Single :py:class:`mlflow.entities.model_registry.ModelVersion` object representing
| the copied model version.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_version_info(mv):
| print(f"Name: {mv.name}")
| print(f"Version: {mv.version}")
| print(f"Source: {mv.source}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
|
| # Log a model
| with mlflow.start_run() as run:
| params = {"n_estimators": 3, "random_state": 42}
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Create source model version
| client = MlflowClient()
| src_name = "RandomForestRegression-staging"
| client.create_registered_model(src_name)
| src_uri = f"runs:/{run.info.run_id}/sklearn-model"
| mv_src = client.create_model_version(src_name, src_uri, run.info.run_id)
| print_model_version_info(mv_src)
| print("--")
|
| # Copy the source model version into a new registered model
| dst_name = "RandomForestRegression-production"
| src_model_uri = f"models:/{mv_src.name}/{mv_src.version}"
| mv_copy = client.copy_model_version(src_model_uri, dst_name)
| print(f"Name: {mv_copy.name}, Version: {mv_copy.version}, Source: {mv_copy.source}")
|
| .. code-block:: python
| :caption: Migration example from Databricks Workspace Model Registry to Unity Catalog
|
| from mlflow import MlflowClient
| import os
|
| os.environ["MLFLOW_SKIP_SIGNATURE_CHECK_FOR_UC_REGISTRY_MIGRATION"] = "true"
| client = MlflowClient(registry_uri="databricks")
|
| src_model_uri = f"models:/my_workspace_model/1"
| uc_model_dst_name = "mycatalog.myschema.my_uc_model"
| uc_migrated_copy = client.copy_model_version(src_model_uri, uc_model_dst_name)
| print_model_version_info(uc_migrated_copy)
|
| .. code-block:: text
| :caption: Output
|
| Name: RandomForestRegression-staging
| Version: 1
| Source: runs:/53e08bb38f0c487fa36c5872515ed998/sklearn-model
| --
| Name: RandomForestRegression-production
| Version: 1
| Source: models:/RandomForestRegression-staging/1
|
| create_dataset(self, name: str, experiment_id: str | list[str] | None = None, tags: dict[str, typing.Any] | None = None) -> mlflow.entities.evaluation_dataset.EvaluationDataset
| Create a new dataset.
|
| Args:
| name: The name of the dataset.
| experiment_id: Optional experiment ID (str) or list of experiment IDs to
| associate with the dataset.
| tags: Optional dictionary of tags to apply to the dataset.
|
| Returns:
| The created EvaluationDataset object.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Create a dataset associated with experiments
| dataset = client.create_dataset(
| name="qa_evaluation_v1",
| experiment_id=["0", "1"],
| tags={"environment": "production", "version": "1.0"},
| )
|
| create_experiment(self, name: str, artifact_location: str | None = None, tags: dict[str, typing.Any] | None = None) -> str
| Create an experiment.
|
| Args:
| name: The experiment name, which must be a unique string.
| artifact_location: The location to store run artifacts. If not provided, the server
| picks anappropriate default.
| tags: A dictionary of key-value pairs that are converted into
| :py:class:`mlflow.entities.ExperimentTag` objects, set as
| experiment tags upon experiment creation.
|
| Returns:
| String as an integer ID of the created experiment.
|
| .. code-block:: python
| :caption: Example
|
| from pathlib import Path
| from mlflow import MlflowClient
|
| # Create an experiment with a name that is unique and case sensitive.
| client = MlflowClient()
| experiment_id = client.create_experiment(
| "Social NLP Experiments",
| artifact_location=Path.cwd().joinpath("mlruns").as_uri(),
| tags={"version": "v1", "priority": "P1"},
| )
| client.set_experiment_tag(experiment_id, "nlp.framework", "Spark NLP")
|
| # Fetch experiment metadata information
| experiment = client.get_experiment(experiment_id)
| print(f"Name: {experiment.name}")
| print(f"Experiment_id: {experiment.experiment_id}")
| print(f"Artifact Location: {experiment.artifact_location}")
| print(f"Tags: {experiment.tags}")
| print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
|
| .. code-block:: text
| :caption: Output
|
| Name: Social NLP Experiments
| Experiment_id: 1
| Artifact Location: file:///.../mlruns
| Tags: {'version': 'v1', 'priority': 'P1', 'nlp.framework': 'Spark NLP'}
| Lifecycle_stage: active
|
| create_logged_model(self, experiment_id: str, name: str | None = None, source_run_id: str | None = None, tags: dict[str, str] | None = None, params: dict[str, str] | None = None, model_type: str | None = None) -> mlflow.entities.logged_model.LoggedModel
| Create a new logged model.
|
| Args:
| experiment_id: ID of the experiment to which the model belongs.
| name: Name of the model. If not specified, a random name will be generated.
| source_run_id: ID of the run that produced the model.
| tags: Tags to set on the model.
| params: Parameters to set on the model.
| model_type: The type of the model. This is a user-defined string that can be used to
| search and compare related models. For example, setting
| ``model_type="agent"`` enables you to easily search for this model and
| compare it to other models of type ``"agent"`` in the future.
|
| Returns:
| The created model.
|
| create_mcp_access_endpoint(self, server_name: str, url: str, transport_type: mlflow.entities.mcp_server.MCPRemoteTransportType = <MCPRemoteTransportType.STREAMABLE_HTTP: 'streamable-http'>, server_version: str | None = None, server_alias: str | None = None) -> mlflow.entities.mcp_access_endpoint.MCPAccessEndpoint
|
| create_mcp_server(self, name: str, description: str | None = None, icons: list[mlflow.store.tracking.mcp_server_registry.abstract_mixin.MCPIcon] | None = None) -> mlflow.entities.mcp_server.MCPServer
|
| create_mcp_server_version(self, server_json: dict[str, typing.Any], source: str | None = None, status: mlflow.entities.mcp_server.MCPStatus | None = None, tools: list[mlflow.entities.mcp_server.MCPTool] | None = <object object at 0x0000025F348EA210>, connect_options: dict[str, mlflow.entities.mcp_server_version.ConnectOptionSettings] | None = None) -> mlflow.entities.mcp_server_version.MCPServerVersion
|
| create_model_version(self, name: str, source: str, run_id: str | None = None, tags: dict[str, typing.Any] | None = None, run_link: str | None = None, description: str | None = None, await_creation_for: int = 300, model_id: str | None = None) -> mlflow.entities.model_registry.model_version.ModelVersion
| Create a new model version from given source.
|
| Args:
| name: Name for the containing registered model.
| source: URI indicating the location of the model artifacts. The artifact URI can be
| run relative (e.g. ``runs:/<run_id>/<model_artifact_path>``), a model
| registry URI (e.g. ``models:/<model_name>/<version>``), or other URIs
| supported by the model registry backend (e.g. `"s3://my_bucket/my/model"`).
| run_id: Run ID from MLflow tracking server that generated the model.
| tags: A dictionary of key-value pairs that are converted into
| :py:class:`mlflow.entities.model_registry.ModelVersionTag` objects.
| run_link: Link to the run from an MLflow tracking server that generated this model.
| description: Description of the version.
| await_creation_for: Number of seconds to wait for the model version to finish being
| created and is in ``READY`` status. By default, the function
| waits for five minutes. Specify 0 or None to skip waiting.
| model_id: The ID of the model (from an Experiment) that is being promoted to a
| registered model version, if applicable.
|
| Returns:
| Single :py:class:`mlflow.entities.model_registry.ModelVersion` object created by
| backend.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow.store.artifact.runs_artifact_repo import RunsArtifactRepository
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a new version of the rfr model under the registered model name
| desc = "A new version of the model"
| runs_uri = f"runs:/{run.info.run_id}/sklearn-model"
| model_src = RunsArtifactRepository.get_underlying_uri(runs_uri)
| mv = client.create_model_version(name, model_src, run.info.run_id, description=desc)
| print(f"Name: {mv.name}")
| print(f"Version: {mv.version}")
| print(f"Description: {mv.description}")
| print(f"Status: {mv.status}")
| print(f"Stage: {mv.current_stage}")
|
| .. code-block:: text
| :caption: Output
|
| Name: RandomForestRegression
| Version: 1
| Description: A new version of the model
| Status: READY
| Stage: None
|
| create_prompt(self, name: str, description: str | None = None, tags: dict[str, str] | None = None) -> mlflow.entities.model_registry.prompt.Prompt
| Create a new prompt in the registry.
|
| This method delegates directly to the store, providing full Unity Catalog support
| when used with Unity Catalog registries.
|
| Args:
| name: Name of the prompt.
| description: Optional description of the prompt.
| tags: Optional dictionary of prompt tags.
|
| Returns:
| A Prompt object.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| prompt_info = client.create_prompt(
| name="my_prompt",
| description="A helpful prompt",
| tags={"team": "data-science"},
| )
|
| create_prompt_version(self, name: str, template: str | list[dict[str, typing.Any]], description: str | None = None, tags: dict[str, str] | None = None, response_format: type[pydantic.main.BaseModel] | dict[str, typing.Any] | None = None, model_config: 'PromptModelConfig | dict[str, Any] | None' = None) -> mlflow.entities.model_registry.prompt_version.PromptVersion
| Create a new version of an existing prompt.
|
| This method delegates directly to the store, providing full Unity Catalog support
| when used with Unity Catalog registries.
|
| Args:
| name: Name of the prompt.
| template: The prompt template content for this version.
| description: Optional description of the prompt version.
| tags: Optional dictionary of prompt version tags.
| response_format: Optional Pydantic class or dictionary defining the expected response
| structure. This can be used to specify the schema for structured
| outputs from LLM calls.
| model_config: Optional PromptModelConfig object or dictionary defining the model
| configuration (model name, parameters, etc.) to use when invoking this
| prompt version.
|
| Returns:
| A PromptVersion object.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| prompt_version = client.create_prompt_version(
| name="my_prompt",
| template="Respond as a {{style}} assistant: {{query}}",
| description="Added style parameter",
| tags={"author": "alice"},
| )
|
| create_registered_model(self, name: str, tags: dict[str, typing.Any] | None = None, description: str | None = None, deployment_job_id: str | None = None) -> mlflow.entities.model_registry.registered_model.RegisteredModel
| Create a new registered model in backend store.
|
| Args:
| name: Name of the new model. This is expected to be unique in the backend store.
| tags: A dictionary of key-value pairs that are converted into
| :py:class:`mlflow.entities.model_registry.RegisteredModelTag` objects.
| description: Description of the model.
| deployment_job_id: Optional deployment job ID.
|
| Returns:
| A single object of :py:class:`mlflow.entities.model_registry.RegisteredModel`
| created by backend.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
|
| def print_registered_model_info(rm):
| print(f"name: {rm.name}")
| print(f"tags: {rm.tags}")
| print(f"description: {rm.description}")
|
|
| name = "SocialMediaTextAnalyzer"
| tags = {"nlp.framework": "Spark NLP"}
| desc = "This sentiment analysis model classifies the tone-happy, sad, angry."
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| client = MlflowClient()
| client.create_registered_model(name, tags, desc)
| print_registered_model_info(client.get_registered_model(name))
|
| .. code-block:: text
| :caption: Output
|
| name: SocialMediaTextAnalyzer
| tags: {'nlp.framework': 'Spark NLP'}
| description: This sentiment analysis model classifies the tone-happy, sad, angry.
|
| create_run(self, experiment_id: str, start_time: int | None = None, tags: dict[str, typing.Any] | None = None, run_name: str | None = None) -> mlflow.entities.run.Run
| Create a :py:class:`mlflow.entities.Run` object that can be associated with
| metrics, parameters, artifacts, etc.
| Unlike :py:func:`mlflow.projects.run`, creates objects but does not run code.
| Unlike :py:func:`mlflow.start_run`, does not change the "active run" used by
| :py:func:`mlflow.log_param`.
|
| Args:
| experiment_id: The string ID of the experiment to create a run in.
| start_time: If not provided, use the current timestamp.
| tags: A dictionary of key-value pairs that are converted into
| :py:class:`mlflow.entities.RunTag` objects.
| run_name: The name of this run.
|
| Returns:
| :py:class:`mlflow.entities.Run` that was created.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| # Create a run with a tag under the default experiment (whose id is '0').
| tags = {"engineering": "ML Platform"}
| name = "platform-run-24"
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id, tags=tags, run_name=name)
|
| # Show newly created run metadata info
| print(f"Run tags: {run.data.tags}")
| print(f"Experiment id: {run.info.experiment_id}")
| print(f"Run id: {run.info.run_id}")
| print(f"Run name: {run.info.run_name}")
| print(f"lifecycle_stage: {run.info.lifecycle_stage}")
| print(f"status: {run.info.status}")
|
| .. code-block:: text
| :caption: Output
|
| Run tags: {'engineering': 'ML Platform'}
| Experiment id: 0
| Run id: 65fb9e2198764354bab398105f2e70c1
| Run name: platform-run-24
| lifecycle_stage: active
| status: RUNNING
|
| create_webhook(self, name: str, url: str, events: list[typing.Union[typing.Literal['registered_model.created', 'model_version.created', 'model_version_tag.set', 'model_version_tag.deleted', 'model_version_alias.created', 'model_version_alias.deleted', 'prompt.created', 'prompt_version.created', 'prompt_tag.set', 'prompt_tag.deleted', 'prompt_version_tag.set', 'prompt_version_tag.deleted', 'prompt_alias.created', 'prompt_alias.deleted', 'budget_policy.exceeded'], mlflow.entities.webhook.WebhookEvent]], description: str | None = None, secret: str | None = None, status: str | mlflow.entities.webhook.WebhookStatus | None = None) -> mlflow.entities.webhook.Webhook
| Create a new webhook.
|
| Args:
| name: Name for the webhook.
| url: Webhook endpoint URL.
| events: List of events that trigger this webhook. Can be strings or
| `WebhookEvent` objects.
| description: Optional description of the webhook.
| secret: Optional secret for HMAC signature verification.
| status: Webhook status (defaults to ACTIVE). Can be string or WebhookStatus enum.
| Valid statuses: "ACTIVE", "DISABLED"
|
| Returns:
| A :py:class:`mlflow.entities.webhook.Webhook` object representing the created webhook.
|
| create_workspace(self, name: str, description: str | None = None, default_artifact_root: str | None = None, trace_archival_config: mlflow.entities.workspace.TraceArchivalConfig | None = None) -> mlflow.entities.workspace.Workspace
| Create a new workspace.
|
| Args:
| name: The workspace name (alphanumeric, hyphens, underscores only).
| description: Optional description of the workspace.
| default_artifact_root: Optional artifact root URI; falls back to server default.
| trace_archival_config: Optional Python-side grouping for trace archival settings.
| Use ``TraceArchivalConfig.location`` to set the archival storage URI/root and
| ``TraceArchivalConfig.retention`` to set the archived-trace retention duration such
| as ``30d`` or ``12h``. Leave fields as ``None`` to omit them from the create
| request.
|
| Returns:
| The newly created workspace.
|
| delete_dataset(self, dataset_id: str) -> None
| Delete a dataset and all its records.
|
| Args:
| dataset_id: The ID of the dataset to delete.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Delete a dataset
| client.delete_dataset("dataset_123")
|
| delete_dataset_tag(self, dataset_id: str, key: str) -> None
| Delete a tag from a dataset.
|
| Args:
| dataset_id: The ID of the dataset.
| key: The tag key to delete.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Delete a tag
| client.delete_dataset_tag(dataset_id="dataset123", key="deprecated")
|
| delete_experiment(self, experiment_id: str) -> None
| Delete an experiment from the backend store.
|
| This deletion is a soft-delete, not a permanent deletion. Experiment names can not be
| reused, unless the deleted experiment is permanently deleted by a database admin.
|
| Args:
| experiment_id: The experiment ID returned from ``create_experiment``.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| # Create an experiment with a name that is unique and case sensitive
| client = MlflowClient()
| experiment_id = client.create_experiment("New Experiment")
| client.delete_experiment(experiment_id)
|
| # Examine the deleted experiment details.
| experiment = client.get_experiment(experiment_id)
| print(f"Name: {experiment.name}")
| print(f"Artifact Location: {experiment.artifact_location}")
| print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
|
| .. code-block:: text
| :caption: Output
|
| Name: New Experiment
| Artifact Location: file:///.../mlruns/1
| Lifecycle_stage: deleted
|
| delete_experiment_tag(self, experiment_id: str, key: str) -> None
| Delete a tag from the experiment with the specified ID.
|
| Args:
| experiment_id: String ID of the experiment.
| key: Name of the tag to be deleted.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| # Create an experiment and set its tag
| client = MlflowClient()
| experiment_id = client.create_experiment("Social Media NLP Experiments")
| client.set_experiment_tag(experiment_id, "nlp.framework", "Spark NLP")
|
| # Fetch experiment metadata information, validate that tag is set
| experiment = client.get_experiment(experiment_id)
| assert experiment.tags == {"nlp.framework": "Spark NLP"}
|
| client.delete_experiment_tag(experiment_id, "nlp.framework")
|
| # Fetch experiment metadata information, validate that tag is deleted
| experiment = client.get_experiment(experiment_id)
| assert experiment.tags == {}
|
| delete_logged_model(self, model_id: str) -> None
| Delete the logged model with the specified ID.
|
| Args:
| model_id: ID of the model to delete.
|
| delete_logged_model_tag(self, model_id: str, key: str) -> None
| Delete a tag from the specified logged model.
|
| Args:
| model_id: ID of the model.
| key: Tag key to delete.
|
| delete_mcp_access_endpoint(self, server_name: str, endpoint_id: str) -> None
|
| delete_mcp_server(self, name: str) -> None
|
| delete_mcp_server_alias(self, name: str, alias: str) -> None
|
| delete_mcp_server_tag(self, name: str, key: str) -> None
|
| delete_mcp_server_version(self, name: str, version: str) -> None
|
| delete_mcp_server_version_tag(self, name: str, version: str, key: str) -> None
|
| delete_model_version(self, name: str, version: str) -> None
| Delete model version in backend.
|
| Args:
| name: Name of the containing registered model.
| version: Version number of the model version.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_models_info(mv):
| for m in mv:
| print(f"name: {m.name}")
| print(f"latest version: {m.version}")
| print(f"run_id: {m.run_id}")
| print(f"current_stage: {m.current_stage}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
|
| # Create two runs and log MLflow entities
| with mlflow.start_run() as run1:
| params = {"n_estimators": 3, "random_state": 42}
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| with mlflow.start_run() as run2:
| params = {"n_estimators": 6, "random_state": 42}
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| name = "RandomForestRegression"
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a two versions of the rfr model under the registered model name
| for run_id in [run1.info.run_id, run2.info.run_id]:
| model_uri = f"runs:/{run_id}/sklearn-model"
| mv = client.create_model_version(name, model_uri, run_id)
| print(f"model version {mv.version} created")
|
| print("--")
|
| # Fetch latest version; this will be version 2
| models = client.get_latest_versions(name, stages=["None"])
| print_models_info(models)
| print("--")
|
| # Delete the latest model version 2
| print(f"Deleting model version {mv.version}")
| client.delete_model_version(name, mv.version)
| models = client.get_latest_versions(name, stages=["None"])
| print_models_info(models)
|
| .. code-block:: text
| :caption: Output
|
| model version 1 created
| model version 2 created
| --
| name: RandomForestRegression
| latest version: 2
| run_id: 9881172ef10f4cb08df3ed452c0c362b
| current_stage: None
| --
| Deleting model version 2
| name: RandomForestRegression
| latest version: 1
| run_id: 9165d4f8aa0a4d069550824bdc55caaf
| current_stage: None
|
| delete_model_version_tag(self, name: str, version: str | None = None, key: str | None = None, stage: str | None = None) -> None
| Delete a tag associated with the model version.
|
| When stage is set, tag will be deleted for latest model version of the stage.
| Setting both version and stage parameter will result in error.
|
| Args:
| name: Registered model name.
| version: Registered model version.
| key: Tag key. key is required.
| stage: Registered model stage.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_version_info(mv):
| print(f"Name: {mv.name}")
| print(f"Version: {mv.version}")
| print(f"Tags: {mv.tags}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a new version of the rfr model under the registered model name
| # and delete a tag
| model_uri = f"runs:/{run.info.run_id}/sklearn-model"
| tags = {"t": "1", "t1": "2"}
| mv = client.create_model_version(name, model_uri, run.info.run_id, tags=tags)
| print_model_version_info(mv)
| print("--")
| # using version to delete tag
| client.delete_model_version_tag(name, mv.version, "t")
|
| # using stage to delete tag
| client.delete_model_version_tag(name, key="t1", stage=mv.current_stage)
| mv = client.get_model_version(name, mv.version)
| print_model_version_info(mv)
|
| .. code-block:: text
| :caption: Output
|
| Name: RandomForestRegression
| Version: 1
| Tags: {'t': '1', 't1': '2'}
| --
| Name: RandomForestRegression
| Version: 1
| Tags: {}
|
| delete_prompt(self, name: str) -> None
| Delete a prompt from the registry.
|
| For Unity Catalog registries, this method first checks if any versions exist for the prompt
| and throws an error if undeleted versions are found. All versions must be explicitly
| deleted first before the prompt itself can be deleted.
|
| For other registries, the prompt is deleted normally without version checking.
|
| Args:
| name: Name of the prompt to delete.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # For Unity Catalog, delete all versions first
| if client.get_registry_uri().startswith("databricks-uc"):
| versions = client.search_prompt_versions("my_prompt")
| for version in versions:
| client.delete_prompt_version("my_prompt", version.version)
|
| # Then delete the prompt
| client.delete_prompt("my_prompt")
|
| delete_prompt_alias(self, name: str, alias: str) -> None
| Delete an alias for a :py:class:`Prompt <mlflow.entities.Prompt>`.
|
| Args:
| name: The name of the prompt.
| alias: The alias to delete for the prompt.
|
| delete_prompt_tag(self, name: str, key: str) -> None
| Delete a tag from a prompt.
|
| This method delegates directly to the store, providing full Unity Catalog support
| when used with Unity Catalog registries.
|
| Args:
| name: Name of the prompt.
| key: Tag key to delete.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| client.delete_prompt_tag("my_prompt", "environment")
|
| delete_prompt_version(self, name: str, version: str) -> None
| Delete a specific prompt version.
|
| This method delegates directly to the store, providing full Unity Catalog support
| when used with Unity Catalog registries.
|
| Args:
| name: Name of the prompt.
| version: Version of the prompt to delete.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| client.delete_prompt_version("my_prompt", "1")
|
| delete_prompt_version_tag(self, name: str, version: str | int, key: str) -> None
| Delete a tag from a specific prompt version.
|
| Args:
| name: The name of the prompt.
| version: The version number of the prompt.
| key: The tag key to delete.
|
| delete_registered_model(self, name: str)
| Delete registered model.
| Backend raises exception if a registered model with given name does not exist.
|
| Args:
| name: Name of the registered model to delete.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
|
| def print_registered_models_info(r_models):
| print("--")
| for rm in r_models:
| print(f"name: {rm.name}")
| print(f"tags: {rm.tags}")
| print(f"description: {rm.description}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| client = MlflowClient()
|
| # Register a couple of models with respective names, tags, and descriptions
| for name, tags, desc in [
| ("name1", {"t1": "t1"}, "description1"),
| ("name2", {"t2": "t2"}, "description2"),
| ]:
| client.create_registered_model(name, tags, desc)
|
| # Fetch all registered models
| print_registered_models_info(client.search_registered_models())
|
| # Delete one registered model and fetch again
| client.delete_registered_model("name1")
| print_registered_models_info(client.search_registered_models())
|
| .. code-block:: text
| :caption: Output
|
| --
| name: name1
| tags: {'t1': 't1'}
| description: description1
| name: name2
| tags: {'t2': 't2'}
| description: description2
| --
| name: name2
| tags: {'t2': 't2'}
| description: description2
|
| delete_registered_model_alias(self, name: str, alias: str) -> None
| Delete an alias associated with a registered model.
|
| Args:
| name: Registered model name.
| alias: Name of the alias.
|
| .. code-block:: Python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_info(rm):
| print("--Model--")
| print("name: {}".format(rm.name))
| print("aliases: {}".format(rm.aliases))
|
|
| def print_model_version_info(mv):
| print("--Model Version--")
| print("Name: {}".format(mv.name))
| print("Version: {}".format(mv.version))
| print("Aliases: {}".format(mv.aliases))
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, artifact_path="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
| model = client.get_registered_model(name)
| print_model_info(model)
|
| # Create a new version of the rfr model under the registered model name
| model_uri = "runs:/{}/sklearn-model".format(run.info.run_id)
| mv = client.create_model_version(name, model_uri, run.info.run_id)
| print_model_version_info(mv)
|
| # Set registered model alias
| client.set_registered_model_alias(name, "test-alias", mv.version)
| print()
| print_model_info(model)
| print_model_version_info(mv)
|
| # Delete registered model alias
| client.delete_registered_model_alias(name, "test-alias")
| print()
| print_model_info(model)
| print_model_version_info(mv)
|
| .. code-block:: text
| :caption: Output
|
| --Model--
| name: RandomForestRegression
| aliases: {}
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: []
|
| --Model--
| name: RandomForestRegression
| aliases: {"test-alias": "1"}
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: ["test-alias"]
|
| --Model--
| name: RandomForestRegression
| aliases: {}
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: []
|
| delete_registered_model_tag(self, name: str, key: str) -> None
| Delete a tag associated with the registered model.
|
| Args:
| name: Registered model name.
| key: Registered model tag key.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
|
| def print_registered_models_info(r_models):
| print("--")
| for rm in r_models:
| print(f"name: {rm.name}")
| print(f"tags: {rm.tags}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| client = MlflowClient()
|
| # Register a couple of models with respective names and tags
| for name, tags in [("name1", {"t1": "t1"}), ("name2", {"t2": "t2"})]:
| client.create_registered_model(name, tags)
|
| # Fetch all registered models
| print_registered_models_info(client.search_registered_models())
| # Delete a tag from model `name2`
| client.delete_registered_model_tag("name2", "t2")
| print_registered_models_info(client.search_registered_models())
|
| .. code-block:: text
| :caption: Output
|
| --
| name: name1
| tags: {'t1': 't1'}
| name: name2
| tags: {'t2': 't2'}
| --
| name: name1
| tags: {'t1': 't1'}
| name: name2
| tags: {}
|
| delete_run(self, run_id: str) -> None
| Deletes a run with the given ID.
|
| Args:
| run_id: The unique run id to delete.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| # Create a run under the default experiment (whose id is '0').
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| run_id = run.info.run_id
| print(f"run_id: {run_id}; lifecycle_stage: {run.info.lifecycle_stage}")
| print("--")
| client.delete_run(run_id)
| del_run = client.get_run(run_id)
| print(f"run_id: {run_id}; lifecycle_stage: {del_run.info.lifecycle_stage}")
|
| .. code-block:: text
| :caption: Output
|
| run_id: a61c7a1851324f7094e8d5014c58c8c8; lifecycle_stage: active
| run_id: a61c7a1851324f7094e8d5014c58c8c8; lifecycle_stage: deleted
|
| delete_tag(self, run_id: str, key: str) -> None
| Delete a tag from a run. This is irreversible.
|
| Args:
| run_id: String ID of the run.
| key: Name of the tag.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_run_info(run):
| print(f"run_id: {run.info.run_id}")
| print(f"Tags: {run.data.tags}")
|
|
| # Create a run under the default experiment (whose id is '0').
| client = MlflowClient()
| tags = {"t1": 1, "t2": 2}
| experiment_id = "0"
| run = client.create_run(experiment_id, tags=tags)
| print_run_info(run)
| print("--")
|
| # Delete tag and fetch updated info
| client.delete_tag(run.info.run_id, "t1")
| run = client.get_run(run.info.run_id)
| print_run_info(run)
|
| .. code-block:: text
| :caption: Output
|
| run_id: b7077267a59a45d78cd9be0de4bc41f5
| Tags: {'t2': '2', 't1': '1'}
| --
| run_id: b7077267a59a45d78cd9be0de4bc41f5
| Tags: {'t2': '2'}
|
| delete_trace_tag(self, trace_id: str, key: str) -> None
| .. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
|
| Delete a tag on the trace with the given trace ID.
|
| The trace can be an active one or the one that has already ended and recorded in the
| backend. Below is an example of deleting a tag on an active trace. You can replace the
| ``trace_id`` parameter to delete a tag on an already ended trace.
|
| .. code-block:: python
| :test:
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| root_span = client.start_trace("my_trace", tags={"key": "value"})
| client.delete_trace_tag(root_span.trace_id, "key")
| client.end_trace(root_span.trace_id)
|
| Args:
| trace_id: The ID of the trace to delete the tag from.
| key: The string key of the tag. Must be at most 250 characters long, otherwise
| it will be truncated when stored.
|
| delete_traces(self, experiment_id: str, max_timestamp_millis: int | None = None, max_traces: int | None = None, trace_ids: list[str] | None = None) -> int
| Delete traces based on the specified criteria.
|
| - Either `max_timestamp_millis` or `trace_ids` must be specified, but not both.
| - `max_traces` can't be specified if `trace_ids` is specified.
|
| Args:
| experiment_id: ID of the associated experiment.
| max_timestamp_millis: The maximum timestamp in milliseconds since the UNIX epoch for
| deleting traces. Traces older than or equal to this timestamp will be deleted.
| max_traces: The maximum number of traces to delete. If max_traces is specified, and
| it is less than the number of traces that would be deleted based on the
| max_timestamp_millis, the oldest traces will be deleted first.
| trace_ids: A set of trace IDs to delete.
|
| Returns:
| The number of traces deleted.
|
| Example:
|
| .. code-block:: python
| :test:
|
| import mlflow
| import time
|
| client = mlflow.MlflowClient()
|
| # Delete all traces in the experiment
| client.delete_traces(
| experiment_id="0", max_timestamp_millis=time.time_ns() // 1_000_000
| )
|
| # Delete traces based on max_timestamp_millis and max_traces
| # Older traces will be deleted first.
| some_timestamp = time.time_ns() // 1_000_000
| client.delete_traces(
| experiment_id="0", max_timestamp_millis=some_timestamp, max_traces=2
| )
|
| # Delete traces based on trace_ids
| client.delete_traces(experiment_id="0", trace_ids=["id_1", "id_2"])
|
| delete_webhook(self, webhook_id: str) -> None
| Delete a webhook.
|
| Args:
| webhook_id: Webhook ID to delete.
|
| Returns:
| None
|
| delete_workspace(self, name: str, mode: str = <WorkspaceDeletionMode.RESTRICT: 'RESTRICT'>) -> None
| Delete an existing workspace.
|
| Args:
| name: Name of the workspace to delete.
| mode: Deletion mode — ``"SET_DEFAULT"``, ``"CASCADE"``, or ``"RESTRICT"``.
|
| detach_prompt_from_run(self, run_id: str, prompt_uri: str) -> None
| Detach a prompt registered within the MLflow Prompt Registry from an MLflow Run.
|
| Args:
| run_id: The ID of the run to log the prompt to.
| prompt_uri: The prompt URI in the format "prompts:/name/version".
|
| download_artifacts(self, run_id: str, path: str, dst_path: str | None = None) -> str
| Download an artifact file or directory from a run to a local directory if applicable,
| and return a local path for it.
|
| Args:
| run_id: The run to download artifacts from.
| path: Relative source path to the desired artifact.
| dst_path: Absolute path of the local filesystem destination directory to which to
| download the specified artifacts. This directory must already exist.
| If unspecified, the artifacts will either be downloaded to a new
| uniquely-named directory on the local filesystem or will be returned
| directly in the case of the LocalArtifactRepository.
|
| Returns:
| Local path of desired artifact.
|
| .. code-block:: python
| :caption: Example
|
| import os
| import mlflow
| from mlflow import MlflowClient
|
| features = "rooms, zipcode, median_price, school_rating, transport"
| with open("features.txt", "w") as f:
| f.write(features)
|
| # Log artifacts
| with mlflow.start_run() as run:
| mlflow.log_artifact("features.txt", artifact_path="features")
|
| # Download artifacts
| client = MlflowClient()
| local_dir = "/tmp/artifact_downloads"
| if not os.path.exists(local_dir):
| os.mkdir(local_dir)
| local_path = client.download_artifacts(run.info.run_id, "features", local_dir)
| print(f"Artifacts downloaded in: {local_path}")
| print(f"Artifacts: {os.listdir(local_path)}")
|
| .. code-block:: text
| :caption: Output
|
| Artifacts downloaded in: /tmp/artifact_downloads/features
| Artifacts: ['features.txt']
|
| end_span(self, trace_id: str, span_id: str, outputs: typing.Any | None = None, attributes: dict[str, typing.Any] | None = None, status: mlflow.entities.span_status.SpanStatus | str = 'OK', end_time_ns: int | None = None)
| .. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
|
| End the span with the given trace ID and span ID.
|
| Args:
| trace_id: The ID of the trace to end.
| span_id: The ID of the span to end.
| outputs: Outputs to set on the span.
| attributes: A dictionary of attributes to set on the span. If the span already has
| attributes, the new attributes will be merged with the existing ones. If the same
| key already exists, the new value will overwrite the old one.
| status: The status of the span. This can be a
| :py:class:`SpanStatus <mlflow.entities.SpanStatus>` object or a string
| representing the status code defined in
| :py:class:`SpanStatusCode <mlflow.entities.SpanStatusCode>`
| e.g. ``"OK"``, ``"ERROR"``. The default status is OK.
| end_time_ns: The end time of the span in nano seconds since the UNIX epoch.
| If not provided, the current time will be used.
|
| end_trace(self, trace_id: str, outputs: typing.Any | None = None, attributes: dict[str, typing.Any] | None = None, status: mlflow.entities.span_status.SpanStatus | str = 'OK', end_time_ns: int | None = None)
| .. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
|
| End the trace with the given trace ID. This will end the root span of the trace and
| log the trace to the backend if configured.
|
| If any of children spans are not ended, they will be ended forcefully with the status
| ``TRACE_STATUS_UNSPECIFIED``. If the trace is already ended, this method will have
| no effect.
|
| Args:
| trace_id: The ID of the trace to end.
| outputs: Outputs to set on the trace.
| attributes: A dictionary of attributes to set on the trace. If the trace already
| has attributes, the new attributes will be merged with the existing ones.
| If the same key already exists, the new value will overwrite the old one.
| status: The status of the trace. This can be a
| :py:class:`SpanStatus <mlflow.entities.SpanStatus>` object or a string
| representing the status code defined in
| :py:class:`SpanStatusCode <mlflow.entities.SpanStatusCode>`
| e.g. ``"OK"``, ``"ERROR"``. The default status is OK.
| end_time_ns: The end time of the trace in nanoseconds since the UNIX epoch.
|
| finalize_logged_model(self, model_id: str, status: Union[Literal['READY', 'FAILED'], mlflow.entities.logged_model_status.LoggedModelStatus]) -> mlflow.entities.logged_model.LoggedModel
| Finalize a model by updating its status.
|
| Args:
| model_id: ID of the model to finalize.
| status: Final status to set on the model.
|
| Returns:
| The updated model.
|
| get_dataset(self, dataset_id: str) -> mlflow.entities.evaluation_dataset.EvaluationDataset
| Get a dataset by ID.
|
| Args:
| dataset_id: The ID of the dataset to retrieve.
|
| Returns:
| The EvaluationDataset object.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Get a dataset by ID (assuming it exists)
| dataset = client.get_dataset("dataset_123")
|
| # Access records (lazy loaded)
| df = dataset.to_df()
|
| get_experiment(self, experiment_id: str) -> mlflow.entities.experiment.Experiment
| Retrieve an experiment by experiment_id from the backend store
|
| Args:
| experiment_id: The experiment ID returned from ``create_experiment``.
|
| Returns:
| :py:class:`mlflow.entities.Experiment`
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| exp_id = client.create_experiment("Experiment")
| experiment = client.get_experiment(exp_id)
|
| # Show experiment info
| print(f"Name: {experiment.name}")
| print(f"Experiment ID: {experiment.experiment_id}")
| print(f"Artifact Location: {experiment.artifact_location}")
| print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
|
| .. code-block:: text
| :caption: Output
|
| Name: Experiment
| Experiment ID: 1
| Artifact Location: file:///.../mlruns/1
| Lifecycle_stage: active
|
| get_experiment_by_name(self, name: str) -> mlflow.entities.experiment.Experiment | None
| Retrieve an experiment by experiment name from the backend store
|
| Args:
| name: The experiment name, which is case sensitive.
|
| Returns:
| An instance of :py:class:`mlflow.entities.Experiment`
| if an experiment with the specified name exists, otherwise None.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| # Case-sensitive name
| client = MlflowClient()
| experiment = client.get_experiment_by_name("Default")
| # Show experiment info
| print(f"Name: {experiment.name}")
| print(f"Experiment ID: {experiment.experiment_id}")
| print(f"Artifact Location: {experiment.artifact_location}")
| print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
|
| .. code-block:: text
| :caption: Output
|
| Name: Default
| Experiment ID: 0
| Artifact Location: file:///.../mlruns/0
| Lifecycle_stage: active
|
| get_latest_mcp_server_version(self, name: str) -> mlflow.entities.mcp_server_version.MCPServerVersion
|
| get_latest_versions(self, name: str, stages: list[str] | None = None) -> list[mlflow.entities.model_registry.model_version.ModelVersion]
| .. Warning:: ``mlflow.tracking.client.MlflowClient.get_latest_versions`` is deprecated since 2.9.0. Model registry stages will be removed in a future major release. To learn more about the deprecation of model registry stages, see our migration guide here: https://mlflow.org/docs/latest/model-registry.html#migrating-from-stages
|
| Latest version models for each requests stage. If no ``stages`` provided, returns the
| latest version for each stage.
|
| Args:
| name: Name of the registered model from which to get the latest versions.
| stages: List of desired stages. If input list is None, return latest versions for
| for ALL_STAGES.
|
| Returns:
| List of :py:class:`mlflow.entities.model_registry.ModelVersion` objects.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_models_info(mv):
| for m in mv:
| print(f"name: {m.name}")
| print(f"latest version: {m.version}")
| print(f"run_id: {m.run_id}")
| print(f"current_stage: {m.current_stage}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| # Create two runs Log MLflow entities
| with mlflow.start_run() as run1:
| params = {"n_estimators": 3, "random_state": 42}
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
| with mlflow.start_run() as run2:
| params = {"n_estimators": 6, "random_state": 42}
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
| # Register model name in the model registry
| name = "RandomForestRegression"
| client = MlflowClient()
| client.create_registered_model(name)
| # Create a two versions of the rfr model under the registered model name
| for run_id in [run1.info.run_id, run2.info.run_id]:
| model_uri = f"runs:/{run_id}/sklearn-model"
| mv = client.create_model_version(name, model_uri, run_id)
| print(f"model version {mv.version} created")
| # Fetch latest version; this will be version 2
| print("--")
| print_models_info(client.get_latest_versions(name, stages=["None"]))
|
| .. code-block:: text
| :caption: Output
|
| model version 1 created
| model version 2 created
| --
| name: RandomForestRegression
| latest version: 2
| run_id: 31165664be034dc698c52a4bdeb71663
| current_stage: None
|
| get_logged_model(self, model_id: str) -> mlflow.entities.logged_model.LoggedModel
| Fetch the logged model with the specified ID.
|
| Args:
| model_id: ID of the model to fetch.
|
| Returns:
| The fetched model.
|
| get_mcp_access_endpoint(self, server_name: str, endpoint_id: str) -> mlflow.entities.mcp_access_endpoint.MCPAccessEndpoint
|
| get_mcp_server(self, name: str) -> mlflow.entities.mcp_server.MCPServer
|
| get_mcp_server_version(self, name: str, version: str) -> mlflow.entities.mcp_server_version.MCPServerVersion
|
| get_mcp_server_version_by_alias(self, name: str, alias: str) -> mlflow.entities.mcp_server_version.MCPServerVersion
|
| get_metric_history(self, run_id: str, key: str) -> list[mlflow.entities.metric.Metric]
| Return a list of metric objects corresponding to all values logged for a given metric.
|
| Args:
| run_id: Unique identifier for run.
| key: Metric name within the run.
|
| Returns:
| A list of :py:class:`mlflow.entities.Metric` entities if logged, else empty list.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_metric_info(history):
| for m in history:
| print(f"name: {m.key}")
| print(f"value: {m.value}")
| print(f"step: {m.step}")
| print(f"timestamp: {m.timestamp}")
| print("--")
|
|
| # Create a run under the default experiment (whose id is "0"). Since this is low-level
| # CRUD operation, the method will create a run. To end the run, you'll have
| # to explicitly end it.
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| print(f"run_id: {run.info.run_id}")
| print("--")
|
| # Log couple of metrics, update their initial value, and fetch each
| # logged metrics' history.
| for k, v in [("m1", 1.5), ("m2", 2.5)]:
| client.log_metric(run.info.run_id, k, v, step=0)
| client.log_metric(run.info.run_id, k, v + 1, step=1)
| print_metric_info(client.get_metric_history(run.info.run_id, k))
| client.set_terminated(run.info.run_id)
|
| .. code-block:: text
| :caption: Output
|
| run_id: c360d15714994c388b504fe09ea3c234
| --
| name: m1
| value: 1.5
| step: 0
| timestamp: 1603423788607
| --
| name: m1
| value: 2.5
| step: 1
| timestamp: 1603423788608
| --
| name: m2
| value: 2.5
| step: 0
| timestamp: 1603423788609
| --
| name: m2
| value: 3.5
| step: 1
| timestamp: 1603423788610
| --
|
| get_model_version(self, name: str, version: str) -> mlflow.entities.model_registry.model_version.ModelVersion
| Converts the docstring args and returns to google style.
|
| Args:
| name: Name of the containing registered model.
| version: Version number as an integer of the model version.
|
| Returns:
| A single :py:class:`mlflow.entities.model_registry.ModelVersion` object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
|
| # Create two runs Log MLflow entities
| with mlflow.start_run() as run1:
| params = {"n_estimators": 3, "random_state": 42}
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| with mlflow.start_run() as run2:
| params = {"n_estimators": 6, "random_state": 42}
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| name = "RandomForestRegression"
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a two versions of the rfr model under the registered model name
| for run_id in [run1.info.run_id, run2.info.run_id]:
| model_uri = f"runs:/{run_id}/sklearn-model"
| mv = client.create_model_version(name, model_uri, run_id)
| print(f"model version {mv.version} created")
| print("--")
|
| # Fetch the last version; this will be version 2
| mv = client.get_model_version(name, mv.version)
| print(f"Name: {mv.name}")
| print(f"Version: {mv.version}")
|
| .. code-block:: text
| :caption: Output
|
| model version 1 created
| model version 2 created
| --
| Name: RandomForestRegression
| Version: 2
|
| get_model_version_by_alias(self, name: str, alias: str) -> mlflow.entities.model_registry.model_version.ModelVersion
| Get the model version instance by name and alias.
|
| Args:
| name: Registered model name.
| alias: Name of the alias.
|
| Returns:
| A single :py:class:`mlflow.entities.model_registry.ModelVersion` object.
|
| .. code-block:: Python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_info(rm):
| print("--Model--")
| print("name: {}".format(rm.name))
| print("aliases: {}".format(rm.aliases))
|
|
| def print_model_version_info(mv):
| print("--Model Version--")
| print("Name: {}".format(mv.name))
| print("Version: {}".format(mv.version))
| print("Aliases: {}".format(mv.aliases))
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, artifact_path="sklearn-model", signature=signature)
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
| model = client.get_registered_model(name)
| print_model_info(model)
| # Create a new version of the rfr model under the registered model name
| model_uri = "runs:/{}/sklearn-model".format(run.info.run_id)
| mv = client.create_model_version(name, model_uri, run.info.run_id)
| print_model_version_info(mv)
| # Set registered model alias
| client.set_registered_model_alias(name, "test-alias", mv.version)
| print()
| print_model_info(model)
| print_model_version_info(mv)
| # Get model version by alias
| alias_mv = client.get_model_version_by_alias(name, "test-alias")
| print()
| print_model_version_info(alias_mv)
|
| .. code-block:: text
| :caption: Output
|
| --Model--
| name: RandomForestRegression
| aliases: {}
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: []
| --Model--
| name: RandomForestRegression
| aliases: {"test-alias": "1"}
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: ["test-alias"]
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: ["test-alias"]
|
| get_model_version_download_uri(self, name: str, version: str) -> str
| Get the download location in Model Registry for this model version.
|
| Args:
| name: Name of the containing registered model.
| version: Version number as an integer of the model version.
|
| Returns:
| A single URI location that allows reads for downloading.
|
| .. code-block:: python
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a new version of the rfr model under the registered model name
| model_uri = f"runs:/{run.info.run_id}/sklearn-model"
| mv = client.create_model_version(name, model_uri, run.info.run_id)
| artifact_uri = client.get_model_version_download_uri(name, mv.version)
| print(f"Download URI: {artifact_uri}")
|
| .. code-block:: text
|
| Download URI: runs:/027d7bbe81924c5a82b3e4ce979fcab7/sklearn-model
|
| get_model_version_stages(self, name: str, version: str) -> list[str]
| .. Warning:: ``mlflow.tracking.client.MlflowClient.get_model_version_stages`` is deprecated since 2.9.0. Model registry stages will be removed in a future major release. To learn more about the deprecation of model registry stages, see our migration guide here: https://mlflow.org/docs/latest/model-registry.html#migrating-from-stages
|
| This is a docstring. Here is info.
|
| Returns:
| A list of valid stages.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a new version of the rfr model under the registered model name
| # fetch valid stages
| model_uri = f"runs:/{run.info.run_id}/models/sklearn-model"
| mv = client.create_model_version(name, model_uri, run.info.run_id)
| stages = client.get_model_version_stages(name, mv.version)
| print(f"Model list of valid stages: {stages}")
|
| .. code-block:: text
| :caption: Output
|
| Model list of valid stages: ['None', 'Staging', 'Production', 'Archived']
|
| get_parent_run(self, run_id: str) -> mlflow.entities.run.Run | None
| Gets the parent run for the given run id if one exists.
|
| Args:
| run_id: Unique identifier for the child run.
|
| Returns:
| A single :py:class:`mlflow.entities.Run` object, if the parent run exists. Otherwise,
| returns None.
|
| .. code-block:: python
| :test:
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
| # Create nested runs
| with mlflow.start_run():
| with mlflow.start_run(nested=True) as child_run:
| child_run_id = child_run.info.run_id
|
| client = MlflowClient()
| parent_run = client.get_parent_run(child_run_id)
|
| print(f"child_run_id: {child_run_id}")
| print(f"parent_run_id: {parent_run.info.run_id}")
|
| .. code-block:: text
| :caption: Output
|
| child_run_id: 7d175204675e40328e46d9a6a5a7ee6a
| parent_run_id: 8979459433a24a52ab3be87a229a9cdf
|
| get_prompt(self, name: str) -> mlflow.entities.model_registry.prompt.Prompt | None
| Get prompt metadata by name.
|
| Args:
| name: Name of the prompt.
|
| Returns:
| A Prompt object containing prompt metadata, or None if not found.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| prompt = client.get_prompt("my_prompt")
| if prompt:
| print(f"Prompt: {prompt.name}")
| print(f"Description: {prompt.description}")
|
| get_prompt_version(self, name: str, version: str | int) -> mlflow.entities.model_registry.prompt_version.PromptVersion | None
| Get a specific prompt version.
|
| This method delegates directly to the store, providing full Unity Catalog support
| when used with Unity Catalog registries.
|
| Args:
| name: Name of the prompt.
| version: Version of the prompt (number or alias).
|
| Returns:
| A PromptVersion object with the specific version content, or None if not found.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| prompt_version = client.get_prompt_version("my_prompt", "1")
| prompt_alias = client.get_prompt_version("my_prompt", "production")
|
| get_prompt_version_by_alias(self, name: str, alias: str) -> mlflow.entities.model_registry.prompt_version.PromptVersion
| Get a prompt version by alias.
|
| This method delegates directly to the store, providing full Unity Catalog support
| when used with Unity Catalog registries.
|
| Args:
| name: Name of the prompt.
| alias: Alias of the prompt version.
|
| Returns:
| A PromptVersion object.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| prompt_version = client.get_prompt_version_by_alias("my_prompt", "production")
|
| get_registered_model(self, name: str) -> mlflow.entities.model_registry.registered_model.RegisteredModel
| Get a registered model.
|
| Args:
| name: Name of the registered model to get.
|
| Returns:
| A single :py:class:`mlflow.entities.model_registry.RegisteredModel` object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
|
| def print_model_info(rm):
| print("--")
| print(f"name: {rm.name}")
| print(f"tags: {rm.tags}")
| print(f"description: {rm.description}")
|
|
| name = "SocialMediaTextAnalyzer"
| tags = {"nlp.framework": "Spark NLP"}
| desc = "This sentiment analysis model classifies the tone-happy, sad, angry."
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| client = MlflowClient()
| # Create and fetch the registered model
| client.create_registered_model(name, tags, desc)
| model = client.get_registered_model(name)
| print_model_info(model)
|
| .. code-block:: text
| :caption: Output
|
| --
| name: SocialMediaTextAnalyzer
| tags: {'nlp.framework': 'Spark NLP'}
| description: This sentiment analysis model classifies the tone-happy, sad, angry.
|
| get_run(self, run_id: str) -> mlflow.entities.run.Run
| Fetch the run from backend store. The resulting :py:class:`Run <mlflow.entities.Run>`
| contains a collection of run metadata -- :py:class:`RunInfo <mlflow.entities.RunInfo>`,
| as well as a collection of run parameters, tags, and metrics --
| :py:class:`RunData <mlflow.entities.RunData>`. It also contains a collection of run
| inputs (experimental), including information about datasets used by the run --
| :py:class:`RunInputs <mlflow.entities.RunInputs>`. In the case where multiple metrics with
| the same key are logged for the run, the :py:class:`RunData <mlflow.entities.RunData>`
| contains the most recently logged value at the largest step for each metric.
|
| Args:
| run_id: Unique identifier for the run.
|
| Returns:
| A single :py:class:`mlflow.entities.Run` object, if the run exists. Otherwise,
| raises an exception.
|
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
| with mlflow.start_run() as run:
| mlflow.log_param("p", 0)
|
| # The run has finished since we have exited the with block
| # Fetch the run
| client = MlflowClient()
| run = client.get_run(run.info.run_id)
| print(f"run_id: {run.info.run_id}")
| print(f"params: {run.data.params}")
| print(f"status: {run.info.status}")
|
| .. code-block:: text
| :caption: Output
|
| run_id: e36b42c587a1413ead7c3b6764120618
| params: {'p': '0'}
| status: FINISHED
|
| get_trace(self, trace_id: str, display=True, flush: bool = False) -> mlflow.entities.trace.Trace
| .. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
|
| Get the trace matching the specified ``trace_id``.
|
| Args:
| trace_id: String ID of the trace to fetch.
| display: If ``True``, display the trace on the notebook.
| flush: If ``True``, flush any pending async trace writes before fetching.
| Useful in tests or scripts where async logging may not have completed.
| Default to ``False``.
|
| Returns:
| The retrieved :py:class:`Trace <mlflow.entities.Trace>`.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| trace_id = "12345678"
| trace = client.get_trace(trace_id)
|
| get_webhook(self, webhook_id: str) -> mlflow.entities.webhook.Webhook
| Get webhook instance by ID.
|
| Args:
| webhook_id: Webhook ID.
|
| Returns:
| A :py:class:`mlflow.entities.webhook.Webhook` object.
|
| get_workspace(self, name: str) -> mlflow.entities.workspace.Workspace
| Return metadata for the specified workspace.
|
| get_workspace_store_uri(self) -> str
| Return the resolved workspace provider URI. This value is always non-null because
| `resolve_workspace_store_uri()` falls back to the tracking URI when no workspace URI is
| explicitly provided.
|
| link_prompt_version_to_model(self, name: str, version: str, model_id: str) -> None
| Link a prompt version to a model.
|
| Args:
| name: The name of the prompt.
| version: The version of the prompt.
| model_id: The ID of the model to link the prompt version to.
|
| link_prompt_version_to_run(self, run_id: str, prompt: str | mlflow.entities.model_registry.prompt_version.PromptVersion) -> None
| Link a prompt registered within the MLflow Prompt Registry with an MLflow Run.
|
| .. warning::
|
| This API is not thread-safe. If you are linking prompts from multiple threads,
| consider using a lock to ensure that only one thread links a prompt to a run at a time.
|
| Args:
| run_id: The ID of the run to link the prompt to.
| prompt: A Prompt object or the prompt URI in the format "prompts:/name/version".
|
| link_prompt_versions_to_trace(self, prompt_versions: list[mlflow.entities.model_registry.prompt_version.PromptVersion], trace_id: str) -> None
| Link multiple prompt versions to a trace.
|
| Args:
| prompt_versions: List of PromptVersion objects to link.
| trace_id: Trace ID to link to each prompt version.
|
| Example:
| .. code-block:: python
|
| import mlflow
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Get prompt versions and link to trace
| prompt_v1 = client.get_prompt_version("my_prompt", "1")
| prompt_v2 = client.get_prompt_version("another_prompt", "2")
|
| client.link_prompt_versions_to_trace(
| prompt_versions=[prompt_v1, prompt_v2],
| trace_id="trace_123",
| )
|
| link_traces_to_run(self, trace_ids: list[str], run_id: str) -> None
| Link multiple traces to a run by creating entity associations.
|
| Args:
| trace_ids: List of trace IDs to link to the run. Maximum 100 traces allowed.
| run_id: ID of the run to link traces to.
|
| Example:
| .. code-block:: python
|
| import mlflow
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Link multiple traces to a run
| client.link_traces_to_run(
| trace_ids=["trace_123", "trace_456", "trace_789"],
| run_id="run_abc",
| )
|
| list_artifacts(self, run_id: str, path=None) -> list[mlflow.entities.file_info.FileInfo]
| List the artifacts for a run.
|
| Args:
| run_id: The run to list artifacts from.
| path: The run's relative artifact path to list from. By default it is set to None
| or the root artifact path.
|
| Returns:
| List of :py:class:`mlflow.entities.FileInfo`
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_artifact_info(artifact):
| print(f"artifact: {artifact.path}")
| print(f"is_dir: {artifact.is_dir}")
| print(f"size: {artifact.file_size}")
|
|
| features = "rooms zipcode, median_price, school_rating, transport"
| labels = "price"
|
| # Create a run under the default experiment (whose id is '0').
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
|
| # Create some artifacts and log under the above run
| for file, content in [("features", features), ("labels", labels)]:
| with open(f"{file}.txt", "w") as f:
| f.write(content)
| client.log_artifact(run.info.run_id, f"{file}.txt")
|
| # Fetch the logged artifacts
| artifacts = client.list_artifacts(run.info.run_id)
| for artifact in artifacts:
| print_artifact_info(artifact)
| client.set_terminated(run.info.run_id)
|
| .. code-block:: text
| :caption: Output
|
| artifact: features.txt
| is_dir: False
| size: 53
| artifact: labels.txt
| is_dir: False
| size: 5
|
| list_logged_model_artifacts(self, model_id: str, path: str | None = None) -> list[mlflow.entities.file_info.FileInfo]
|
| list_logged_prompts(self, run_id: str) -> list[mlflow.entities.model_registry.prompt_version.PromptVersion]
| List all prompts associated with an MLflow Run.
|
| Args:
| run_id: The ID of the run to list the prompts for.
|
| Returns:
| A list of :py:class:`Prompt <mlflow.entities.Prompt>` objects associated with the run.
|
| list_webhooks(self, max_results: int | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.webhook.Webhook]
| List webhooks.
|
| Args:
| max_results: Maximum number of webhooks to return.
| page_token: Token specifying the next page of results.
|
| Returns:
| A :py:class:`mlflow.store.entities.paged_list.PagedList` of Webhook objects.
|
| list_workspaces(self) -> list[mlflow.entities.workspace.Workspace]
| Return the list of workspaces available to the current user.
|
| load_prompt(self, name_or_uri: str, version: str | int | None = None, allow_missing: bool = False, cache_ttl_seconds: float | None = None) -> mlflow.entities.model_registry.prompt_version.PromptVersion | None
| Load a :py:class:`Prompt <mlflow.entities.Prompt>` from the MLflow Prompt Registry.
|
| The prompt can be specified by name and version, or by URI.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient(registry_uri="sqlite:///prompt_registry.db")
|
| # Load a specific version of the prompt by name and version
| prompt = client.load_prompt("my_prompt", version=1)
|
| # Load a specific version of the prompt by URI
| prompt = client.load_prompt("prompts:/my_prompt/1")
|
| Args:
| name_or_uri: The name of the prompt, or the URI in the format "prompts:/name/version".
| version: The version of the prompt (required when using name, not allowed when
| using URI).
| allow_missing: If True, return None instead of raising Exception if the specified prompt
| is not found.
| cache_ttl_seconds: Time-to-live for caching the prompt in seconds. If None, uses
| the value from `MLFLOW_ALIAS_PROMPT_CACHE_TTL_SECONDS` environment variable for
| alias-based prompts (default 60), and the value from
| `MLFLOW_VERSION_PROMPT_CACHE_TTL_SECONDS` environment variable for version-based
| prompts (default None, no TTL). Set to 0 to disable caching.
|
| load_table(self, experiment_id: str, artifact_file: str, run_ids: list[str] | None = None, extra_columns: list[str] | None = None) -> 'pandas.DataFrame'
| Load a table from MLflow Tracking as a pandas.DataFrame. The table is loaded from the
| specified artifact_file in the specified run_ids. The extra_columns are columns that
| are not in the table but are augmented with run information and added to the DataFrame.
|
| Args:
| experiment_id: The experiment ID to load the table from.
| artifact_file: The run-relative artifact file path in posixpath format to which
| table to load (e.g. "dir/file.json").
| run_ids: Optional list of run_ids to load the table from. If no run_ids are
| specified, the table is loaded from all runs in the current experiment.
| extra_columns: Optional list of extra columns to add to the returned DataFrame
| For example, if extra_columns=["run_id"], then the returned DataFrame
| will have a column named run_id.
|
| Returns:
| pandas.DataFrame containing the loaded table if the artifact exists
| or else throw a MlflowException.
|
| .. code-block:: python
| :test:
| :caption: Example with passing run_ids
|
| import mlflow
| import pandas as pd
| from mlflow import MlflowClient
|
| table_dict = {
| "inputs": ["What is MLflow?", "What is Databricks?"],
| "outputs": ["MLflow is ...", "Databricks is ..."],
| "toxicity": [0.0, 0.0],
| }
| df = pd.DataFrame.from_dict(table_dict)
| client = MlflowClient()
| run = client.create_run(experiment_id="0")
| client.log_table(run.info.run_id, data=df, artifact_file="qabot_eval_results.json")
| loaded_table = client.load_table(
| experiment_id="0",
| artifact_file="qabot_eval_results.json",
| run_ids=[
| run.info.run_id,
| ],
| # Append a column containing the associated run ID for each row
| extra_columns=["run_id"],
| )
|
| .. code-block:: python
| :test:
| :caption: Example with passing no run_ids
|
| # Loads the table with the specified name for all runs in the given
| # experiment and joins them together
| import mlflow
| import pandas as pd
| from mlflow import MlflowClient
|
| table_dict = {
| "inputs": ["What is MLflow?", "What is Databricks?"],
| "outputs": ["MLflow is ...", "Databricks is ..."],
| "toxicity": [0.0, 0.0],
| }
| df = pd.DataFrame.from_dict(table_dict)
| client = MlflowClient()
| run = client.create_run(experiment_id="0")
| client.log_table(run.info.run_id, data=df, artifact_file="qabot_eval_results.json")
| loaded_table = client.load_table(
| experiment_id="0",
| artifact_file="qabot_eval_results.json",
| # Append the run ID and the parent run ID to the table
| extra_columns=["run_id"],
| )
|
| log_artifact(self, run_id, local_path, artifact_path=None) -> None
| Write a local file or directory to the remote ``artifact_uri``.
|
| Args:
| run_id: String ID of run.
| local_path: Path to the file or directory to write.
| artifact_path: If provided, the directory in ``artifact_uri`` to write to.
|
| .. code-block:: python
| :caption: Example
|
| import tempfile
| from pathlib import Path
|
| from mlflow import MlflowClient
|
| # Create a run under the default experiment (whose id is '0').
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
|
| # log and fetch the artifact
| with tempfile.TemporaryDirectory() as tmp_dir:
| path = Path(tmp_dir, "features.txt")
| path.write_text(features)
| client.log_artifact(run.info.run_id, path)
|
| artifacts = client.list_artifacts(run.info.run_id)
| for artifact in artifacts:
| print(f"artifact: {artifact.path}")
| print(f"is_dir: {artifact.is_dir}")
| client.set_terminated(run.info.run_id)
|
| .. code-block:: text
| :caption: Output
|
| artifact: features.txt
| is_dir: False
|
| log_artifacts(self, run_id: str, local_dir: str, artifact_path: str | None = None) -> None
| Write a directory of files to the remote ``artifact_uri``.
|
| Args:
| run_id: String ID of run.
| local_dir: Path to the directory of files to write.
| artifact_path: If provided, the directory in ``artifact_uri`` to write to.
|
| .. code-block:: python
| :caption: Example
|
| import json
| import tempfile
| from pathlib import Path
|
| # Create some artifacts data to preserve
| features = "rooms, zipcode, median_price, school_rating, transport"
| data = {"state": "TX", "Available": 25, "Type": "Detached"}
| with tempfile.TemporaryDirectory() as tmp_dir:
| tmp_dir = Path(tmp_dir)
| with (tmp_dir / "data.json").open("w") as f:
| json.dump(data, f, indent=2)
| with (tmp_dir / "features.json").open("w") as f:
| f.write(features)
|
| # Create a run under the default experiment (whose id is '0'), and log
| # all files in "data" to root artifact_uri/states
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| client.log_artifacts(run.info.run_id, tmp_dir, artifact_path="states")
|
| artifacts = client.list_artifacts(run.info.run_id)
| for artifact in artifacts:
| print(f"artifact: {artifact.path}")
| print(f"is_dir: {artifact.is_dir}")
| client.set_terminated(run.info.run_id)
|
| .. code-block:: text
| :caption: Output
|
| artifact: states
| is_dir: True
|
| log_batch(self, run_id: str, metrics: Sequence[mlflow.entities.metric.Metric] = (), params: Sequence[mlflow.entities.param.Param] = (), tags: Sequence[mlflow.entities.run_tag.RunTag] = (), synchronous: bool | None = None) -> mlflow.utils.async_logging.run_operations.RunOperations | None
| Log multiple metrics, params, and/or tags.
|
| Args:
| run_id: String ID of the run
| metrics: If provided, List of Metric(key, value, timestamp) instances.
| params: If provided, List of Param(key, value) instances.
| tags: If provided, List of RunTag(key, value) instances.
| synchronous: *Experimental* If True, blocks until the metric is logged successfully.
| If False, logs the metric asynchronously and returns a future representing the
| logging operation. If None, read from environment variable
| `MLFLOW_ENABLE_ASYNC_LOGGING`, which defaults to False if not set.
|
| Raises:
| mlflow.MlflowException: If any errors occur.
|
| Returns:
| When `synchronous=True` or None, returns None. When `synchronous=False`, returns an
| :py:class:`mlflow.utils.async_logging.run_operations.RunOperations` instance that
| represents future for logging operation.
|
| .. code-block:: python
| :caption: Example
|
| import time
|
| from mlflow import MlflowClient
| from mlflow.entities import Metric, Param, RunTag
|
|
| def print_run_info(r):
| print(f"run_id: {r.info.run_id}")
| print(f"params: {r.data.params}")
| print(f"metrics: {r.data.metrics}")
| print(f"tags: {r.data.tags}")
| print(f"status: {r.info.status}")
|
|
| # Create MLflow entities and a run under the default experiment (whose id is '0').
| timestamp = int(time.time() * 1000)
| metrics = [Metric("m", 1.5, timestamp, 1)]
| params = [Param("p", "p")]
| tags = [RunTag("t", "t")]
| experiment_id = "0"
| client = MlflowClient()
| run = client.create_run(experiment_id)
|
| # Log entities, terminate the run, and fetch run status
| client.log_batch(run.info.run_id, metrics=metrics, params=params, tags=tags)
| client.set_terminated(run.info.run_id)
| run = client.get_run(run.info.run_id)
| print_run_info(run)
|
| # To log metric in async fashion
| client.log_metric(run.info.run_id, "m", 1.5, synchronous=False)
|
| .. code-block:: text
| :caption: Output
|
| run_id: ef0247fa3205410595acc0f30f620871
| params: {'p': 'p'}
| metrics: {'m': 1.5}
| tags: {'t': 't'}
| status: FINISHED
|
| log_dict(self, run_id: str, dictionary: dict[str, typing.Any], artifact_file: str) -> None
| Log a JSON/YAML-serializable object (e.g. `dict`) as an artifact. The serialization
| format (JSON or YAML) is automatically inferred from the extension of `artifact_file`.
| If the file extension doesn't exist or match any of [".json", ".yml", ".yaml"],
| JSON format is used, and we stringify objects that can't be JSON-serialized.
|
| Args:
| run_id: String ID of the run.
| dictionary: Dictionary to log.
| artifact_file: The run-relative artifact file path in posixpath format to which
| the dictionary is saved (e.g. "dir/data.json").
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| run = client.create_run(experiment_id="0")
| run_id = run.info.run_id
|
| dictionary = {"k": "v"}
|
| # Log a dictionary as a JSON file under the run's root artifact directory
| client.log_dict(run_id, dictionary, "data.json")
|
| # Log a dictionary as a YAML file in a subdirectory of the run's root artifact directory
| client.log_dict(run_id, dictionary, "dir/data.yml")
|
| # If the file extension doesn't exist or match any of [".json", ".yaml", ".yml"],
| # JSON format is used.
| mlflow.log_dict(run_id, dictionary, "data")
| mlflow.log_dict(run_id, dictionary, "data.txt")
|
| log_figure(self, run_id: str, figure: Union[ForwardRef('matplotlib.figure.Figure'), ForwardRef('plotly.graph_objects.Figure')], artifact_file: str, *, save_kwargs: dict[str, typing.Any] | None = None) -> None
| Log a figure as an artifact. The following figure objects are supported:
|
| - `matplotlib.figure.Figure`_
| - `plotly.graph_objects.Figure`_
|
| .. _matplotlib.figure.Figure:
| https://matplotlib.org/api/_as_gen/matplotlib.figure.Figure.html
|
| .. _plotly.graph_objects.Figure:
| https://plotly.com/python-api-reference/generated/plotly.graph_objects.Figure.html
|
| Args:
| run_id: String ID of the run.
| figure: Figure to log.
| artifact_file: The run-relative artifact file path in posixpath format to which
| the figure is saved (e.g. "dir/file.png").
| save_kwargs: Additional keyword arguments passed to the method that saves the figure.
|
| .. code-block:: python
| :caption: Matplotlib Example
|
| import mlflow
| import matplotlib.pyplot as plt
|
| fig, ax = plt.subplots()
| ax.plot([0, 1], [2, 3])
|
| run = client.create_run(experiment_id="0")
| client.log_figure(run.info.run_id, fig, "figure.png")
|
| .. code-block:: python
| :caption: Plotly Example
|
| import mlflow
| from plotly import graph_objects as go
|
| fig = go.Figure(go.Scatter(x=[0, 1], y=[2, 3]))
|
| run = client.create_run(experiment_id="0")
| client.log_figure(run.info.run_id, fig, "figure.html")
|
| log_image(self, run_id: str, image: Union[ForwardRef('numpy.ndarray'), ForwardRef('PIL.Image.Image'), ForwardRef('mlflow.Image')], artifact_file: str | None = None, key: str | None = None, step: int | None = None, timestamp: int | None = None, synchronous: bool | None = None) -> None
| Logs an image in MLflow, supporting two use cases:
|
| 1. Time-stepped image logging:
| Ideal for tracking changes or progressions through iterative processes (e.g.,
| during model training phases).
|
| - Usage: :code:`log_image(image, key=key, step=step, timestamp=timestamp)`
|
| 2. Artifact file image logging:
| Best suited for static image logging where the image is saved directly as a file
| artifact.
|
| - Usage: :code:`log_image(image, artifact_file)`
|
| The following image formats are supported:
| - `numpy.ndarray`_
| - `PIL.Image.Image`_
|
| .. _numpy.ndarray:
| https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html
|
| .. _PIL.Image.Image:
| https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image
|
| - :class:`mlflow.Image`: An MLflow wrapper around PIL image for convenient image
| logging.
|
| Numpy array support
| - data types:
|
| - bool (useful for logging image masks)
| - integer [0, 255]
| - unsigned integer [0, 255]
| - float [0.0, 1.0]
|
| .. warning::
|
| - Out-of-range integer values will raise ValueError.
| - Out-of-range float values will auto-scale with min/max and warn.
|
| - shape (H: height, W: width):
|
| - H x W (Grayscale)
| - H x W x 1 (Grayscale)
| - H x W x 3 (an RGB channel order is assumed)
| - H x W x 4 (an RGBA channel order is assumed)
|
| Args:
| run_id: String ID of run.
| image: The image object to be logged.
| artifact_file: Specifies the path, in POSIX format, where the image
| will be stored as an artifact relative to the run's root directory (for
| example, "dir/image.png"). This parameter is kept for backward compatibility
| and should not be used together with `key`, `step`, or `timestamp`.
| key: Image name for time-stepped image logging. This string may only contain
| alphanumerics, underscores (_), dashes (-), periods (.), spaces ( ), and
| slashes (/).
| step: Integer training step (iteration) at which the image was saved.
| Defaults to 0.
| timestamp: Time when this image was saved. Defaults to the current system time.
| synchronous: *Experimental* If True, blocks until the metric is logged successfully.
| If False, logs the metric asynchronously and returns a future representing the
| logging operation. If None, read from environment variable
| `MLFLOW_ENABLE_ASYNC_LOGGING`, which defaults to False if not set.
|
| .. code-block:: python
| :caption: Time-stepped image logging numpy example
|
| import mlflow
| import numpy as np
|
| image = np.random.randint(0, 256, size=(100, 100, 3), dtype=np.uint8)
| with mlflow.start_run() as run:
| client = mlflow.MlflowClient()
| client.log_image(run.info.run_id, image, key="dogs", step=3)
|
| .. code-block:: python
| :caption: Time-stepped image logging pillow example
|
| import mlflow
| from PIL import Image
|
| image = Image.new("RGB", (100, 100))
| with mlflow.start_run() as run:
| client = mlflow.MlflowClient()
| client.log_image(run.info.run_id, image, key="dogs", step=3)
|
| .. code-block:: python
| :caption: Time-stepped image logging with mlflow.Image example
|
| import mlflow
| from PIL import Image
|
| # Saving an image to retrieve later.
| Image.new("RGB", (100, 100)).save("image.png")
|
| image = mlflow.Image("image.png")
| with mlflow.start_run() as run:
| client = mlflow.MlflowClient()
| client.log_image(run.info.run_id, image, key="dogs", step=3)
|
| .. code-block:: python
| :caption: Legacy artifact file image logging numpy example
|
| import mlflow
| import numpy as np
|
| image = np.random.randint(0, 256, size=(100, 100, 3), dtype=np.uint8)
| with mlflow.start_run() as run:
| client = mlflow.MlflowClient()
| client.log_image(run.info.run_id, image, "image.png")
|
| .. code-block:: python
| :caption: Legacy artifact file image logging pillow example
|
| import mlflow
| from PIL import Image
|
| image = Image.new("RGB", (100, 100))
| with mlflow.start_run() as run:
| client = mlflow.MlflowClient()
| client.log_image(run.info.run_id, image, "image.png")
|
| log_inputs(self, run_id: str, datasets: Optional[Sequence[mlflow.entities.dataset_input.DatasetInput]] = None, models: Optional[Sequence[mlflow.entities.logged_model_input.LoggedModelInput]] = None) -> None
| Log one or more dataset inputs to a run.
|
| Args:
| run_id: String ID of the run.
| datasets: List of :py:class:`mlflow.entities.DatasetInput` instances to log.
| models: List of :py:class:`mlflow.entities.LoggedModelInput` instances to log.
|
| Raises:
| mlflow.MlflowException: If any errors occur.
|
| log_metric(self, run_id: str, key: str, value: float, timestamp: int | None = None, step: int | None = None, synchronous: bool | None = None, dataset_name: str | None = None, dataset_digest: str | None = None, model_id: str | None = None) -> mlflow.utils.async_logging.run_operations.RunOperations | None
| Log a metric against the run ID.
|
| Args:
| run_id: The run id to which the metric should be logged.
| key: Metric name. This string may only contain alphanumerics, underscores
| (_), dashes (-), periods (.), spaces ( ), and slashes (/).
| All backend stores will support keys up to length 250, but some may
| support larger keys.
| value: Metric value. Note that some special values such
| as +/- Infinity may be replaced by other values depending on the store. For
| example, the SQLAlchemy store replaces +/- Inf with max / min float values.
| All backend stores will support values up to length 5000, but some
| may support larger values.
| timestamp: Time when this metric was calculated. Defaults to the current system time.
| step: Integer training step (iteration) at which was the metric calculated.
| Defaults to 0.
| synchronous: *Experimental* If True, blocks until the metric is logged successfully.
| If False, logs the metric asynchronously and returns a future representing the
| logging operation. If None, read from environment variable
| `MLFLOW_ENABLE_ASYNC_LOGGING`, which defaults to False if not set.
| dataset_name: The name of the dataset associated with the metric. If specified,
| ``dataset_digest`` must also be provided.
| dataset_digest: The digest of the dataset associated with the metric. If specified,
| ``dataset_name`` must also be provided.
| model_id: The ID of the model associated with the metric. If not specified, use the
| current active model ID set by :py:func:`mlflow.set_active_model`.
|
| Returns:
| When `synchronous=True` or None, returns None. When `synchronous=False`, returns an
| :py:class:`mlflow.utils.async_logging.run_operations.RunOperations` instance that
| represents future for logging operation.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_run_info(r):
| print(f"run_id: {r.info.run_id}")
| print(f"metrics: {r.data.metrics}")
| print(f"status: {r.info.status}")
|
|
| # Create a run under the default experiment (whose id is '0').
| # Since these are low-level CRUD operations, this method will create a run.
| # To end the run, you'll have to explicitly end it.
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| print_run_info(run)
| print("--")
|
| # Log the metric. Unlike mlflow.log_metric this method
| # does not start a run if one does not exist. It will log
| # the metric for the run id in the backend store.
| client.log_metric(run.info.run_id, "m", 1.5)
| client.set_terminated(run.info.run_id)
| run = client.get_run(run.info.run_id)
| print_run_info(run)
|
| # To log metric in async fashion
| client.log_metric(run.info.run_id, "m", 1.5, synchronous=False)
|
| .. code-block:: text
| :caption: Output
|
| run_id: 95e79843cb2c463187043d9065185e24
| metrics: {}
| status: RUNNING
| --
| run_id: 95e79843cb2c463187043d9065185e24
| metrics: {'m': 1.5}
| status: FINISHED
|
| log_model_artifact(self, model_id: str, local_path: str) -> None
| Upload an artifact to the specified logged model.
|
| Args:
| model_id: ID of the model.
| local_path: Local path to the artifact to upload.
|
| Returns:
| None
|
| log_model_artifacts(self, model_id: str, local_dir: str) -> None
| Upload a set of artifacts to the specified logged model.
|
| Args:
| model_id: ID of the model.
| local_dir: Local directory containing the artifacts to upload.
|
| Returns:
| None
|
| log_model_params(self, model_id: str, params: dict[str, str]) -> None
| Log parameters for a logged model.
|
| Args:
| model_id: ID of the model to log parameters for.
| params: Dictionary of parameters to log.
|
| Returns:
| None
|
| log_outputs(self, run_id: str, models: list[mlflow.entities.logged_model_output.LoggedModelOutput])
|
| log_param(self, run_id: str, key: str, value: Any, synchronous: bool | None = None) -> Any
| Log a parameter (e.g. model hyperparameter) against the run ID.
|
| Args:
| run_id: The run id to which the param should be logged.
| key: Parameter name. This string may only contain alphanumerics, underscores
| (_), dashes (-), periods (.), spaces ( ), and slashes (/).
| All backend stores support keys up to length 250, but some may
| support larger keys.
| value: Parameter value, but will be string-ified if not.
| All built-in backend stores support values up to length 6000, but some
| may support larger values.
| synchronous: *Experimental* If True, blocks until the metric is logged successfully.
| If False, logs the metric asynchronously and returns a future representing the
| logging operation. If None, read from environment variable
| `MLFLOW_ENABLE_ASYNC_LOGGING`, which defaults to False if not set.
|
| Returns:
| When `synchronous=True` or None, returns parameter value. When `synchronous=False`,
| returns an :py:class:`mlflow.utils.async_logging.run_operations.RunOperations`
| instance that represents future for logging operation.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_run_info(r):
| print(f"run_id: {r.info.run_id}")
| print(f"params: {r.data.params}")
| print(f"status: {r.info.status}")
|
|
| # Create a run under the default experiment (whose id is '0').
| # Since these are low-level CRUD operations, this method will create a run.
| # To end the run, you'll have to explicitly end it.
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| print_run_info(run)
| print("--")
| # Log the parameter. Unlike mlflow.log_param this method
| # does not start a run if one does not exist. It will log
| # the parameter in the backend store
| p_value = client.log_param(run.info.run_id, "p", 1)
| assert p_value == 1
| client.set_terminated(run.info.run_id)
| run = client.get_run(run.info.run_id)
| print_run_info(run)
|
| .. code-block:: text
| :caption: Output
|
| run_id: e649e49c7b504be48ee3ae33c0e76c93
| params: {}
| status: RUNNING
| --
| run_id: e649e49c7b504be48ee3ae33c0e76c93
| params: {'p': '1'}
| status: FINISHED
|
| log_stream(self, run_id: str, stream: io.BufferedIOBase | io.RawIOBase, artifact_file: str) -> None
| .. Note:: Experimental: This function may change or be removed in a future release without warning.
|
|
| Log a binary file-like object (e.g., ``io.BytesIO``) as an artifact.
|
| Args:
| run_id: String ID of the run.
| stream: A binary file-like object supporting ``.read()`` method
| (e.g., ``io.BytesIO``).
| artifact_file: The run-relative artifact file path in posixpath format to which
| the stream content is saved (e.g. "dir/file.bin").
|
| .. code-block:: python
| :caption: Example
|
| import io
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| run = client.create_run(experiment_id="0")
|
| # Log a BytesIO stream
| bytes_stream = io.BytesIO(b"binary content")
| client.log_stream(run.info.run_id, bytes_stream, "binary_file.bin")
|
| log_table(self, run_id: str, data: Union[dict[str, Any], ForwardRef('pandas.DataFrame')], artifact_file: str) -> None
| Log a table to MLflow Tracking as a JSON artifact. If the artifact_file already exists
| in the run, the data would be appended to the existing artifact_file.
|
| Args:
| run_id: String ID of the run.
| data: Dictionary or pandas.DataFrame to log.
| artifact_file: The run-relative artifact file path in posixpath format to which
| the table is saved (e.g. "dir/file.json").
|
| .. code-block:: python
| :test:
| :caption: Dictionary Example
|
| import mlflow
| from mlflow import MlflowClient
|
| table_dict = {
| "inputs": ["What is MLflow?", "What is Databricks?"],
| "outputs": ["MLflow is ...", "Databricks is ..."],
| "toxicity": [0.0, 0.0],
| }
| with mlflow.start_run() as run:
| client = MlflowClient()
| client.log_table(
| run.info.run_id, data=table_dict, artifact_file="qabot_eval_results.json"
| )
|
| .. code-block:: python
| :test:
| :caption: Pandas DF Example
|
| import mlflow
| import pandas as pd
| from mlflow import MlflowClient
|
| table_dict = {
| "inputs": ["What is MLflow?", "What is Databricks?"],
| "outputs": ["MLflow is ...", "Databricks is ..."],
| "toxicity": [0.0, 0.0],
| }
| df = pd.DataFrame.from_dict(table_dict)
| with mlflow.start_run() as run:
| client = MlflowClient()
| client.log_table(run.info.run_id, data=df, artifact_file="qabot_eval_results.json")
|
| .. code-block:: python
| :test:
| :caption: Image Column Example
|
| import mlflow
| import pandas as pd
| from mlflow import MlflowClient
|
| image = mlflow.Image([[1, 2, 3]])
| table_dict = {
| "inputs": ["Show me a dog", "Show me a cat"],
| "outputs": [image, image],
| }
| df = pd.DataFrame.from_dict(table_dict)
| with mlflow.start_run() as run:
| client = MlflowClient()
| client.log_table(run.info.run_id, data=df, artifact_file="image_gen.json")
|
| log_text(self, run_id: str, text: str, artifact_file: str) -> None
| Log text as an artifact.
|
| Args:
| run_id: String ID of the run.
| text: String containing text to log.
| artifact_file: The run-relative artifact file path in posixpath format to which
| the text is saved (e.g. "dir/file.txt").
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| run = client.create_run(experiment_id="0")
|
| # Log text to a file under the run's root artifact directory
| client.log_text(run.info.run_id, "text1", "file1.txt")
|
| # Log text in a subdirectory of the run's root artifact directory
| client.log_text(run.info.run_id, "text2", "dir/file2.txt")
|
| # Log HTML text
| client.log_text(run.info.run_id, "<h1>header</h1>", "index.html")
|
| parse_prompt_uri(self, uri: str) -> tuple[str, str]
| Parse prompt URI into prompt name and prompt version.
| - 'prompts:/<name>/<version>' -> ('<name>', '<version>')
| - 'prompts:/<name>@<alias>' -> ('<name>', '<version>')
|
| This method reuses the existing model URI parsing logic with prompts prefix.
|
| refresh_mcp_server_version_tools(self, name: str, version: str, mcp_server_access_headers: Optional[Mapping[str, str]] = None, dry_run: bool = False) -> mlflow.entities.mcp_server_version.MCPServerVersion
|
| register_prompt(self, name: str, template: str | list[dict[str, typing.Any]], commit_message: str | None = None, tags: dict[str, str] | None = None, response_format: type[pydantic.main.BaseModel] | dict[str, typing.Any] | None = None, model_config: 'PromptModelConfig | dict[str, Any] | None' = None) -> mlflow.entities.model_registry.prompt_version.PromptVersion
| Register a new :py:class:`Prompt <mlflow.entities.Prompt>` in the MLflow Prompt Registry.
|
| A :py:class:`Prompt <mlflow.entities.Prompt>` is a pair of name
| and template content at minimum. With MLflow Prompt Registry, you can create, manage,
| and version control prompts with the MLflow's robust model tracking framework.
|
| If there is no registered prompt with the given name, a new prompt will be created.
| Otherwise, a new version of the existing prompt will be created.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
| from pydantic import BaseModel
|
| # Your prompt registry URI
| client = MlflowClient(registry_uri="sqlite:///prompt_registry.db")
|
| # Register a text prompt
| client.register_prompt(
| name="greeting_prompt",
| template="Respond to the user's message as a {{style}} AI.",
| response_format={"type": "string", "description": "A friendly response"},
| )
|
| # Register a chat prompt with multiple messages
| client.register_prompt(
| name="assistant_prompt",
| template=[
| {"role": "system", "content": "You are a helpful {{style}} assistant."},
| {"role": "user", "content": "{{question}}"},
| ],
| response_format={"type": "object", "properties": {"answer": {"type": "string"}}},
| )
|
| # Load the prompt from the registry
| prompt = client.load_prompt("greeting_prompt")
|
| # Use the prompt in your application
| import openai
|
| openai_client = openai.OpenAI()
| openai_client.chat.completion.create(
| model="gpt-4o-mini",
| messages=[
| {"role": "system", "content": prompt.format(style="friendly")},
| {"role": "user", "content": "Hello, how are you?"},
| ],
| )
|
| # Update the prompt with a new version
| prompt = client.register_prompt(
| name="greeting_prompt",
| template="Respond to the user's message as a {{style}} AI. {{greeting}}",
| commit_message="Add a greeting to the prompt.",
| tags={"author": "Bob"},
| )
|
| Args:
| name: The name of the prompt.
| template: The template content of the prompt. Can be either:
|
| - A string containing text with variables enclosed in double curly braces,
| e.g. {{variable}}, which will be replaced with actual values by the `format`
| method.
| - A list of dictionaries representing chat messages, where each message has
| 'role' and 'content' keys (e.g., [{"role": "user", "content": "Hello {{name}}"}])
|
| commit_message: A message describing the changes made to the prompt, similar to a
| Git commit message. Optional.
| tags: A dictionary of tags for the prompt.
| These tags are stored on the prompt version and written to prompt-level metadata.
| For OSS, later ``register_prompt()`` calls can overwrite the same keys at the
| prompt level. Optional.
| response_format: Optional Pydantic class or dictionary defining the expected response
| structure. This can be used to specify the schema for structured outputs from LLM
| calls.
| model_config: Optional PromptModelConfig instance or dictionary containing
| model-specific configuration like model_name, temperature, max_tokens, etc.
| Using PromptModelConfig provides validation and type safety.
|
| Returns:
| A :py:class:`Prompt <mlflow.entities.Prompt>` object that was created.
|
| remove_dataset_from_experiments(self, dataset_id: str, experiment_ids: list[str]) -> mlflow.entities.evaluation_dataset.EvaluationDataset
| Remove a dataset from experiments.
|
| This operation is idempotent - removing non-existent associations will not raise errors.
|
| Args:
| dataset_id: The ID of the dataset to update.
| experiment_ids: List of experiment IDs to remove association from.
|
| Returns:
| The updated EvaluationDataset with removed experiment associations.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Remove dataset from experiments
| dataset = client.remove_dataset_from_experiments(
| dataset_id="d-abc123", experiment_ids=["2", "3"]
| )
| print(f"Dataset now associated with {len(dataset.experiment_ids)} experiments")
|
| rename_experiment(self, experiment_id: str, new_name: str) -> None
| Update an experiment's name. The new name must be unique.
|
| Args:
| experiment_id: The experiment ID returned from ``create_experiment``.
| new_name: The new name for the experiment.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_experiment_info(experiment):
| print(f"Name: {experiment.name}")
| print(f"Experiment_id: {experiment.experiment_id}")
| print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
|
|
| # Create an experiment with a name that is unique and case sensitive
| client = MlflowClient()
| experiment_id = client.create_experiment("Social NLP Experiments")
|
| # Fetch experiment metadata information
| experiment = client.get_experiment(experiment_id)
| print_experiment_info(experiment)
| print("--")
|
| # Rename and fetch experiment metadata information
| client.rename_experiment(experiment_id, "Social Media NLP Experiments")
| experiment = client.get_experiment(experiment_id)
| print_experiment_info(experiment)
|
| .. code-block:: text
| :caption: Output
|
| Name: Social NLP Experiments
| Experiment_id: 1
| Lifecycle_stage: active
| --
| Name: Social Media NLP Experiments
| Experiment_id: 1
| Lifecycle_stage: active
|
| rename_registered_model(self, name: str, new_name: str) -> mlflow.entities.model_registry.registered_model.RegisteredModel
| Update registered model name.
|
| Args:
| name: Name of the registered model to update.
| new_name: New proposed name for the registered model.
|
| Returns:
| A single updated :py:class:`mlflow.entities.model_registry.RegisteredModel` object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
|
| def print_registered_model_info(rm):
| print(f"name: {rm.name}")
| print(f"tags: {rm.tags}")
| print(f"description: {rm.description}")
|
|
| name = "SocialTextAnalyzer"
| tags = {"nlp.framework": "Spark NLP"}
| desc = "This sentiment analysis model classifies the tone-happy, sad, angry."
|
| # create a new registered model name
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| client = MlflowClient()
| client.create_registered_model(name, tags, desc)
| print_registered_model_info(client.get_registered_model(name))
| print("--")
|
| # rename the model
| new_name = "SocialMediaTextAnalyzer"
| client.rename_registered_model(name, new_name)
| print_registered_model_info(client.get_registered_model(new_name))
|
| .. code-block:: text
| :caption: Output
|
| name: SocialTextAnalyzer
| tags: {'nlp.framework': 'Spark NLP'}
| description: This sentiment analysis model classifies the tone-happy, sad, angry.
| --
| name: SocialMediaTextAnalyzer
| tags: {'nlp.framework': 'Spark NLP'}
| description: This sentiment analysis model classifies the tone-happy, sad, angry.
|
| restore_experiment(self, experiment_id: str) -> None
| Restore a deleted experiment unless permanently deleted.
|
| Args:
| experiment_id: The experiment ID returned from ``create_experiment``.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_experiment_info(experiment):
| print(f"Name: {experiment.name}")
| print(f"Experiment Id: {experiment.experiment_id}")
| print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
|
|
| # Create and delete an experiment
| client = MlflowClient()
| experiment_id = client.create_experiment("New Experiment")
| client.delete_experiment(experiment_id)
|
| # Examine the deleted experiment details.
| experiment = client.get_experiment(experiment_id)
| print_experiment_info(experiment)
| print("--")
|
| # Restore the experiment and fetch its info
| client.restore_experiment(experiment_id)
| experiment = client.get_experiment(experiment_id)
| print_experiment_info(experiment)
|
| .. code-block:: text
| :caption: Output
|
| Name: New Experiment
| Experiment Id: 1
| Lifecycle_stage: deleted
| --
| Name: New Experiment
| Experiment Id: 1
| Lifecycle_stage: active
|
| restore_run(self, run_id: str) -> None
| Restores a deleted run with the given ID.
|
| Args:
| run_id: The unique run id to restore.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| # Create a run under the default experiment (whose id is '0').
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| run_id = run.info.run_id
| print(f"run_id: {run_id}; lifecycle_stage: {run.info.lifecycle_stage}")
| client.delete_run(run_id)
| del_run = client.get_run(run_id)
| print(f"run_id: {run_id}; lifecycle_stage: {del_run.info.lifecycle_stage}")
| client.restore_run(run_id)
| rest_run = client.get_run(run_id)
| print(f"run_id: {run_id}; lifecycle_stage: {rest_run.info.lifecycle_stage}")
|
| .. code-block:: text
| :caption: Output
|
| run_id: 7bc59754d7e74534a7917d62f2873ac0; lifecycle_stage: active
| run_id: 7bc59754d7e74534a7917d62f2873ac0; lifecycle_stage: deleted
| run_id: 7bc59754d7e74534a7917d62f2873ac0; lifecycle_stage: active
|
| search_datasets(self, experiment_ids: list[str] | None = None, filter_string: str | None = None, max_results: int = 50, order_by: list[str] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.evaluation_dataset.EvaluationDataset]
| Search for datasets.
|
| Args:
| experiment_ids: List of experiment IDs to filter by.
| filter_string: A filter string to apply to the search.
| max_results: Maximum number of results to return. Defaults to 50.
| order_by: List of columns to order by.
| page_token: Token for the next page of results.
|
| Returns:
| A PagedList of EvaluationDataset objects.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Search for datasets in specific experiments
| datasets = client.search_datasets(
| experiment_ids=["exp1", "exp2"], filter_string="name LIKE 'qa_%'", max_results=10
| )
|
| # Get next page if available
| if datasets.token:
| next_page = client.search_datasets(
| experiment_ids=["exp1", "exp2"], page_token=datasets.token
| )
|
| search_experiments(self, view_type: int = 1, max_results: int | None = 1000, filter_string: str | None = None, order_by: list[str] | None = None, page_token=None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.experiment.Experiment]
| Search for experiments that match the specified search query.
|
| Args:
| view_type: One of enum values ``ACTIVE_ONLY``, ``DELETED_ONLY``, or ``ALL``
| defined in :py:class:`mlflow.entities.ViewType`.
| max_results: Maximum number of experiments desired. Certain server backend may apply
| its own limit.
| filter_string: Filter query string (e.g., ``"name = 'my_experiment'"``), defaults to
| searching for all experiments. The following identifiers, comparators, and logical
| operators are supported.
|
| Identifiers
| - ``name``: Experiment name
| - ``creation_time``: Experiment creation time
| - ``last_update_time``: Experiment last update time
| - ``tags.<tag_key>``: Experiment tag. If ``tag_key`` contains
| spaces, it must be wrapped with backticks (e.g., ``"tags.`extra key`"``).
|
| Comparators for string attributes and tags
| - ``=``: Equal to
| - ``!=``: Not equal to
| - ``LIKE``: Case-sensitive pattern match
| - ``ILIKE``: Case-insensitive pattern match
|
| Comparators for numeric attributes
| - ``=``: Equal to
| - ``!=``: Not equal to
| - ``<``: Less than
| - ``<=``: Less than or equal to
| - ``>``: Greater than
| - ``>=``: Greater than or equal to
|
| Logical operators
| - ``AND``: Combines two sub-queries and returns True if both of them are True.
|
| order_by: List of columns to order by. The ``order_by`` column can contain an optional
| ``DESC`` or ``ASC`` value (e.g., ``"name DESC"``). The default ordering is ``ASC``,
| so ``"name"`` is equivalent to ``"name ASC"``. If unspecified, defaults to
| ``["last_update_time DESC"]``, which lists experiments updated most recently first.
| The following fields are supported:
|
| - ``experiment_id``: Experiment ID
| - ``name``: Experiment name
| - ``creation_time``: Experiment creation time
| - ``last_update_time``: Experiment last update time
|
| page_token: Token specifying the next page of results. It should be obtained from
| a ``search_experiments`` call.
|
| Returns:
| A :py:class:`PagedList <mlflow.store.entities.PagedList>` of
| :py:class:`Experiment <mlflow.entities.Experiment>` objects. The pagination token
| for the next page can be obtained via the ``token`` attribute of the object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
|
|
| def assert_experiment_names_equal(experiments, expected_names):
| actual_names = [e.name for e in experiments if e.name != "Default"]
| assert actual_names == expected_names, (actual_names, expected_names)
|
|
| mlflow.set_tracking_uri("sqlite:///:memory:")
| client = mlflow.MlflowClient()
|
| # Create experiments
| for name, tags in [
| ("a", None),
| ("b", None),
| ("ab", {"k": "v"}),
| ("bb", {"k": "V"}),
| ]:
| client.create_experiment(name, tags=tags)
|
| # Search for experiments with name "a"
| experiments = client.search_experiments(filter_string="name = 'a'")
| assert_experiment_names_equal(experiments, ["a"])
|
| # Search for experiments with name starting with "a"
| experiments = client.search_experiments(filter_string="name LIKE 'a%'")
| assert_experiment_names_equal(experiments, ["ab", "a"])
|
| # Search for experiments with tag key "k" and value ending with "v" or "V"
| experiments = client.search_experiments(filter_string="tags.k ILIKE '%v'")
| assert_experiment_names_equal(experiments, ["bb", "ab"])
|
| # Search for experiments with name ending with "b" and tag {"k": "v"}
| experiments = client.search_experiments(filter_string="name LIKE '%b' AND tags.k = 'v'")
| assert_experiment_names_equal(experiments, ["ab"])
|
| # Sort experiments by name in ascending order
| experiments = client.search_experiments(order_by=["name"])
| assert_experiment_names_equal(experiments, ["a", "ab", "b", "bb"])
|
| # Sort experiments by ID in descending order
| experiments = client.search_experiments(order_by=["experiment_id DESC"])
| assert_experiment_names_equal(experiments, ["bb", "ab", "b", "a"])
|
| search_logged_models(self, experiment_ids: list[str], filter_string: str | None = None, datasets: list[dict[str, typing.Any]] | None = None, max_results: int | None = None, order_by: list[dict[str, typing.Any]] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.logged_model.LoggedModel]
| Search for logged models that match the specified search criteria.
|
| Args:
| experiment_ids: List of experiment ids to scope the search.
| filter_string: A SQL-like filter string to parse. The filter string syntax supports:
|
| - Entity specification:
| - attributes: `attribute_name` (default if no prefix is specified)
| - metrics: `metrics.metric_name`
| - parameters: `params.param_name`
| - tags: `tags.tag_name`
| - Comparison operators:
| - For numeric entities (metrics and numeric attributes): <, <=, >, >=, =, !=
| - For string entities (params, tags, string attributes): =, !=, IN, NOT IN
| - Multiple conditions can be joined with 'AND'
| - String values must be enclosed in single quotes
|
| Example filter strings:
| - `creation_time > 100`
| - `metrics.rmse > 0.5 AND params.model_type = 'rf'`
| - `tags.release IN ('v1.0', 'v1.1')`
| - `params.optimizer != 'adam' AND metrics.accuracy >= 0.9`
| datasets: List of dictionaries to specify datasets on which to apply metrics filters
| For example, a filter string with `metrics.accuracy > 0.9` and dataset with name
| "test_dataset" means we will return all logged models with accuracy > 0.9 on the
| test_dataset. Metric values from ANY dataset matching the criteria are considered.
| If no datasets are specified, then metrics across all datasets are considered in
| the filter. The following fields are supported:
|
| dataset_name (str):
| Required. Name of the dataset.
| dataset_digest (str):
| Optional. Digest of the dataset.
| max_results: Maximum number of logged models desired.
| order_by: List of dictionaries to specify the ordering of the search results.
| The following fields are supported:
|
| field_name (str):
| Required. Name of the field to order by, e.g. "metrics.accuracy".
| ascending (bool):
| Optional. Whether the order is ascending or not.
| dataset_name (str):
| Optional. If ``field_name`` refers to a metric, this field
| specifies the name of the dataset associated with the metric. Only metrics
| associated with the specified dataset name will be considered for ordering.
| This field may only be set if ``field_name`` refers to a metric.
| dataset_digest (str):
| Optional. If ``field_name`` refers to a metric, this field
| specifies the digest of the dataset associated with the metric. Only metrics
| associated with the specified dataset name and digest will be considered for
| ordering. This field may only be set if ``dataset_name`` is also set.
| page_token: Token specifying the next page of results.
|
| Returns:
| A :py:class:`PagedList <mlflow.store.entities.PagedList>` of
| :py:class:`LoggedModel <mlflow.entities.LoggedModel>` objects.
|
| search_mcp_access_endpoints(self, server_name: str | None = None, server_version: str | None = None, server_alias: str | None = None, filter_string: str | None = None, max_results: int = 1000, order_by: list[str] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.mcp_access_endpoint.MCPAccessEndpoint]
|
| search_mcp_server_versions(self, name: str, filter_string: str | None = None, max_results: int = 1000, order_by: list[str] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.mcp_server_version.MCPServerVersion]
|
| search_mcp_servers(self, filter_string: str | None = None, max_results: int = 1000, order_by: list[str] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.mcp_server.MCPServer]
|
| search_model_versions(self, filter_string: str | None = None, max_results: int = 10000, order_by: list[str] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.model_registry.model_version.ModelVersion]
| Search for model versions in backend that satisfy the filter criteria.
|
| .. warning:
| The model version search results may not have aliases populated for performance reasons.
|
| Args:
| filter_string: Filter query string
| (e.g., ``"name = 'a_model_name' and tag.key = 'value1'"``),
| defaults to searching for all model versions. The following identifiers,
| comparators, and logical operators are supported.
|
| Identifiers
| - ``name``: model name.
| - ``source_path``: model version source path.
| - ``run_id``: The id of the mlflow run that generates the model version.
| - ``tags.<tag_key>``: model version tag. If ``tag_key`` contains spaces, it must
| be wrapped with backticks (e.g., ``"tags.`extra key`"``).
|
| Comparators
| - ``=``: Equal to.
| - ``!=``: Not equal to.
| - ``LIKE``: Case-sensitive pattern match.
| - ``ILIKE``: Case-insensitive pattern match.
| - ``IN``: In a value list. Only ``run_id`` identifier supports ``IN`` comparator.
|
| Logical operators
| - ``AND``: Combines two sub-queries and returns True if both of them are True.
|
| max_results: Maximum number of model versions desired.
| order_by: List of column names with ASC|DESC annotation, to be used for ordering
| matching search results.
| page_token: Token specifying the next page of results. It should be obtained from
| a ``search_model_versions`` call.
|
| Returns:
| A PagedList of :py:class:`mlflow.entities.model_registry.ModelVersion`
| objects that satisfy the search expressions. The pagination token for the next
| page can be obtained via the ``token`` attribute of the object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Get all versions of the model filtered by name
| model_name = "CordobaWeatherForecastModel"
| filter_string = f"name='{model_name}'"
| results = client.search_model_versions(filter_string)
| print("-" * 80)
| for res in results:
| print(f"name={res.name}; run_id={res.run_id}; version={res.version}")
|
| # Get the version of the model filtered by run_id
| run_id = "e14afa2f47a040728060c1699968fd43"
| filter_string = f"run_id='{run_id}'"
| results = client.search_model_versions(filter_string)
| print("-" * 80)
| for res in results:
| print(f"name={res.name}; run_id={res.run_id}; version={res.version}")
|
| .. code-block:: text
| :caption: Output
|
| ------------------------------------------------------------------------------------
| name=CordobaWeatherForecastModel; run_id=eaef868ee3d14d10b4299c4c81ba8814; version=1
| name=CordobaWeatherForecastModel; run_id=e14afa2f47a040728060c1699968fd43; version=2
| ------------------------------------------------------------------------------------
| name=CordobaWeatherForecastModel; run_id=e14afa2f47a040728060c1699968fd43; version=2
|
| search_prompt_versions(self, name: str, max_results: int | None = None, page_token: str | None = None)
| Search prompt versions for a given prompt name.
|
| Args:
| name: Name of the prompt to search versions for.
| max_results: Maximum number of versions to return.
| page_token: Token for pagination.
|
| Returns:
| A :py:class:`PagedList <mlflow.store.entities.PagedList>` of
| :py:class:`~mlflow.entities.model_registry.PromptVersion` objects.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| versions = client.search_prompt_versions("my_prompt", max_results=10)
| for version in versions:
| print(f"Version {version.version}: {version.template}")
|
| search_prompts(self, filter_string: str | None = None, max_results: int = 1000, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.model_registry.prompt.Prompt]
| Search for prompts in the MLflow Prompt Registry.
|
| This call returns prompt metadata for prompts that have been marked
| as prompts (i.e. tagged with `mlflow.prompt.is_prompt=true`). We can
| further restrict results via a standard registry filter expression.
|
| Args:
| filter_string (Optional[str]):
| An additional registry-search expression to apply (e.g.
| `"name LIKE 'my_prompt%'"`). For Unity Catalog registries, must include
| catalog and schema: "catalog = 'catalog_name' AND schema = 'schema_name'".
| max_results (int):
| The maximum number of prompts to return in one page. Defaults
| to `SEARCH_MAX_RESULTS_DEFAULT` (typically 1 000).
| page_token (Optional[str]):
| A pagination token from a previous `search_prompts` call; use this
| to retrieve the next page of results. Defaults to `None`.
|
| Returns:
| A pageable list of :py:class:`Prompt <mlflow.entities.Prompt>` objects
| representing prompt metadata:
|
| - name: The prompt name
| - description: The prompt description
| - tags: Prompt-level tags
| - creation_timestamp: When the prompt was created
|
| To get the actual prompt template content,
| use get_prompt_version() with a specific version:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| # Your prompt registry URI
| client = MlflowClient(registry_uri="sqlite:///prompt_registry.db")
|
| # Search for prompts
| prompts = client.search_prompts(filter_string="name LIKE 'greeting%'")
|
| # Get prompts by experiment
| prompts = client.search_prompts(filter_string='experiment_id = "1"')
|
| # Get specific version content
| for prompt in prompts:
| prompt_version = client.get_prompt_version(prompt.name, version="1")
| print(f"Template: {prompt_version.template}")
|
| Inspect the returned object's `.token` attribute to fetch subsequent pages.
|
| search_registered_models(self, filter_string: str | None = None, max_results: int = 100, order_by: list[str] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.model_registry.registered_model.RegisteredModel]
| Search for registered models in backend that satisfy the filter criteria.
|
| Args:
| filter_string: Filter query string (e.g., "name = 'a_model_name' and tag.key =
| 'value1'"), defaults to searching for all registered models. The following
| identifiers, comparators, and logical operators are supported.
|
| Identifiers
| - ``name``: registered model name.
| - ``tags.<tag_key>``: registered model tag. If ``tag_key`` contains spaces, it
| must be wrapped with backticks (e.g., "tags.`extra key`").
|
| Comparators
| - ``=``: Equal to.
| - ``!=``: Not equal to.
| - ``LIKE``: Case-sensitive pattern match.
| - ``ILIKE``: Case-insensitive pattern match.
|
| Logical operators
| - ``AND``: Combines two sub-queries and returns True if both of them are True.
|
| max_results: Maximum number of registered models desired.
| order_by: List of column names with ASC|DESC annotation, to be used for ordering
| matching search results.
| page_token: Token specifying the next page of results. It should be obtained from
| a ``search_registered_models`` call.
|
| Returns:
| A PagedList of :py:class:`mlflow.entities.model_registry.RegisteredModel` objects
| that satisfy the search expressions. The pagination token for the next page can be
| obtained via the ``token`` attribute of the object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Get search results filtered by the registered model name
| model_name = "CordobaWeatherForecastModel"
| filter_string = f"name='{model_name}'"
| results = client.search_registered_models(filter_string=filter_string)
| print("-" * 80)
| for res in results:
| for mv in res.latest_versions:
| print(f"name={mv.name}; run_id={mv.run_id}; version={mv.version}")
|
| # Get search results filtered by the registered model name that matches
| # prefix pattern
| filter_string = "name LIKE 'Boston%'"
| results = client.search_registered_models(filter_string=filter_string)
| print("-" * 80)
| for res in results:
| for mv in res.latest_versions:
| print(f"name={mv.name}; run_id={mv.run_id}; version={mv.version}")
|
| # Get all registered models and order them by ascending order of the names
| results = client.search_registered_models(order_by=["name ASC"])
| print("-" * 80)
| for res in results:
| for mv in res.latest_versions:
| print(f"name={mv.name}; run_id={mv.run_id}; version={mv.version}")
|
| .. code-block:: text
| :caption: Output
|
| ------------------------------------------------------------------------------------
| name=CordobaWeatherForecastModel; run_id=eaef868ee3d14d10b4299c4c81ba8814; version=1
| name=CordobaWeatherForecastModel; run_id=e14afa2f47a040728060c1699968fd43; version=2
| ------------------------------------------------------------------------------------
| name=BostonWeatherForecastModel; run_id=ddc51b9407a54b2bb795c8d680e63ff6; version=1
| name=BostonWeatherForecastModel; run_id=48ac94350fba40639a993e1b3d4c185d; version=2
| -----------------------------------------------------------------------------------
| name=AzureWeatherForecastModel; run_id=5fcec6c4f1c947fc9295fef3fa21e52d; version=1
| name=AzureWeatherForecastModel; run_id=8198cb997692417abcdeb62e99052260; version=3
| name=BostonWeatherForecastModel; run_id=ddc51b9407a54b2bb795c8d680e63ff6; version=1
| name=BostonWeatherForecastModel; run_id=48ac94350fba40639a993e1b3d4c185d; version=2
| name=CordobaWeatherForecastModel; run_id=eaef868ee3d14d10b4299c4c81ba8814; version=1
| name=CordobaWeatherForecastModel; run_id=e14afa2f47a040728060c1699968fd43; version=2
|
| search_runs(self, experiment_ids: list[str], filter_string: str = '', run_view_type: int = 1, max_results: int = 1000, order_by: list[str] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.run.Run]
| Search for Runs that fit the specified criteria.
|
| Args:
| experiment_ids: List of experiment IDs, or a single int or string id.
| filter_string: Filter query string, defaults to searching all runs.
| run_view_type: one of enum values ACTIVE_ONLY, DELETED_ONLY, or ALL runs
| defined in :py:class:`mlflow.entities.ViewType`.
| max_results: Maximum number of runs desired.
| order_by: List of columns to order by (e.g., "metrics.rmse"). The ``order_by`` column
| can contain an optional ``DESC`` or ``ASC`` value. The default is ``ASC``.
| The default ordering is to sort by ``start_time DESC``, then ``run_id``.
| page_token: Token specifying the next page of results. It should be obtained from
| a ``search_runs`` call.
|
| Returns:
| A :py:class:`PagedList <mlflow.store.entities.PagedList>` of
| :py:class:`Run <mlflow.entities.Run>` objects that satisfy the search expressions.
| If the underlying tracking store supports pagination, the token for the next page may
| be obtained via the ``token`` attribute of the returned object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
| from mlflow.entities import ViewType
|
|
| def print_run_info(runs):
| for r in runs:
| print(f"run_id: {r.info.run_id}")
| print(f"lifecycle_stage: {r.info.lifecycle_stage}")
| print(f"metrics: {r.data.metrics}")
| # Exclude mlflow system tags
| tags = {k: v for k, v in r.data.tags.items() if not k.startswith("mlflow.")}
| print(f"tags: {tags}")
|
|
| # Create an experiment and log two runs with metrics and tags under the experiment
| experiment_id = mlflow.create_experiment("Social NLP Experiments")
| with mlflow.start_run(experiment_id=experiment_id) as run:
| mlflow.log_metric("m", 1.55)
| mlflow.set_tag("s.release", "1.1.0-RC")
| with mlflow.start_run(experiment_id=experiment_id):
| mlflow.log_metric("m", 2.50)
| mlflow.set_tag("s.release", "1.2.0-GA")
| # Search all runs under experiment id and order them by
| # descending value of the metric 'm'
| client = MlflowClient()
| runs = client.search_runs(experiment_id, order_by=["metrics.m DESC"])
| print_run_info(runs)
| print("--")
| # Delete the first run
| client.delete_run(run_id=run.info.run_id)
| # Search only deleted runs under the experiment id and use a case insensitive pattern
| # in the filter_string for the tag.
| filter_string = "tags.s.release ILIKE '%rc%'"
| runs = client.search_runs(
| experiment_id, run_view_type=ViewType.DELETED_ONLY, filter_string=filter_string
| )
| print_run_info(runs)
|
| .. code-block:: text
| :caption: Output
|
| run_id: 0efb2a68833d4ee7860a964fad31cb3f
| lifecycle_stage: active
| metrics: {'m': 2.5}
| tags: {'s.release': '1.2.0-GA'}
| run_id: 7ab027fd72ee4527a5ec5eafebb923b8
| lifecycle_stage: active
| metrics: {'m': 1.55}
| tags: {'s.release': '1.1.0-RC'}
| --
| run_id: 7ab027fd72ee4527a5ec5eafebb923b8
| lifecycle_stage: deleted
| metrics: {'m': 1.55}
| tags: {'s.release': '1.1.0-RC'}
|
| search_traces(self, experiment_ids: list[str] | None = None, filter_string: str | None = None, max_results: int = 100, order_by: list[str] | None = None, page_token: str | None = None, run_id: str | None = None, include_spans: bool = True, model_id: str | None = None, locations: list[str] | None = None, flush: bool = False) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.trace.Trace]
| .. Note:: Parameter ``experiment_ids`` is deprecated. Use ``locations`` instead.
|
| Return traces that match the given list of search expressions within the experiments.
|
| Args:
| experiment_ids: List of experiment ids to scope the search.
| filter_string: A search filter string.
| max_results: Maximum number of traces desired.
| order_by: List of order_by clauses.
| page_token: Token specifying the next page of results. It should be obtained from
| a ``search_traces`` call.
| run_id: A run id to scope the search. When a trace is created under an active run,
| it will be associated with the run and you can filter on the run id to retrieve
| the trace.
| include_spans: If ``True``, include spans in the returned traces. Otherwise, only
| the trace metadata is returned, e.g., trace ID, start time, end time, etc,
| without any spans.
| model_id: If specified, return traces associated with the model ID.
| locations: A list of locations to search over. To search over experiments, provide
| a list of experiment IDs. To search over UC tables on databricks, provide
| a list of locations in the format `<catalog_name>.<schema_name>`.
| flush: If ``True``, flush any pending async trace writes before searching.
| Useful in tests or scripts to ensure all traces are visible. Default to ``False``.
|
| Returns:
| A :py:class:`PagedList <mlflow.store.entities.PagedList>` of
| :py:class:`Trace <mlflow.entities.Trace>` objects that satisfy the search
| expressions. If the underlying tracking store supports pagination, the token for the
| next page may be obtained via the ``token`` attribute of the returned object; however,
| some store implementations may not support pagination and thus the returned token would
| not be meaningful in such cases.
|
| set_dataset_tags(self, dataset_id: str, tags: dict[str, typing.Any]) -> None
| Set tags for a dataset.
|
| This implements an upsert operation - existing tags are merged with new tags.
| To remove a tag, set its value to None.
|
| Args:
| dataset_id: The ID of the dataset to update.
| tags: Dictionary of tags to update. Setting a value to None removes the tag.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Set tags for a dataset
| client.set_dataset_tags(
| dataset_id="dataset123",
| tags={
| "environment": "production",
| "version": "2.0",
| "deprecated": None, # This removes the 'deprecated' tag
| },
| )
|
| set_experiment_tag(self, experiment_id: str, key: str, value: Any) -> None
| Set a tag on the experiment with the specified ID. Value is converted to a string.
|
| Args:
| experiment_id: String ID of the experiment.
| key: Name of the tag.
| value: Tag value (converted to a string).
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| # Create an experiment and set its tag
| client = MlflowClient()
| experiment_id = client.create_experiment("Social Media NLP Experiments")
| client.set_experiment_tag(experiment_id, "nlp.framework", "Spark NLP")
|
| # Fetch experiment metadata information
| experiment = client.get_experiment(experiment_id)
| print(f"Name: {experiment.name}")
| print(f"Tags: {experiment.tags}")
|
| .. code-block:: text
|
| Name: Social Media NLP Experiments
| Tags: {'nlp.framework': 'Spark NLP'}
|
| set_logged_model_tags(self, model_id: str, tags: dict[str, typing.Any]) -> None
| Set tags on the specified logged model.
|
| Args:
| model_id: ID of the model.
| tags: Tags to set on the model.
|
| Returns:
| None
|
| set_mcp_server_alias(self, name: str, alias: str, version: str) -> None
|
| set_mcp_server_tag(self, name: str, key: str, value: str) -> None
|
| set_mcp_server_version_tag(self, name: str, version: str, key: str, value: str) -> None
|
| set_model_version_tag(self, name: str, version: str | None = None, key: str | None = None, value: Any = None, stage: str | None = None) -> None
| Set a tag for the model version.
| When stage is set, tag will be set for latest model version of the stage.
| Setting both version and stage parameter will result in error.
|
| Args:
| name: Registered model name.
| version: Registered model version.
| key: Tag key to log. key is required.
| value: Tag value to log. value is required.
| stage: Registered model stage.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_version_info(mv):
| print(f"Name: {mv.name}")
| print(f"Version: {mv.version}")
| print(f"Tags: {mv.tags}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a new version of the rfr model under the registered model name
| # and set a tag
| model_uri = f"runs:/{run.info.run_id}/sklearn-model"
| mv = client.create_model_version(name, model_uri, run.info.run_id)
| print_model_version_info(mv)
| print("--")
|
| # Tag using model version
| client.set_model_version_tag(name, mv.version, "t", "1")
|
| # Tag using model stage
| client.set_model_version_tag(name, key="t1", value="1", stage=mv.current_stage)
| mv = client.get_model_version(name, mv.version)
| print_model_version_info(mv)
|
| .. code-block:: text
| :caption: Output
|
| Name: RandomForestRegression
| Version: 1
| Tags: {}
| --
| Name: RandomForestRegression
| Version: 1
| Tags: {'t': '1', 't1': '1'}
|
| set_prompt_alias(self, name: str, alias: str, version: int) -> None
| Set an alias for a :py:class:`Prompt <mlflow.entities.Prompt>`.
|
| Args:
| name: The name of the prompt.
| alias: The alias to set for the prompt.
| version: The version of the prompt.
|
| set_prompt_tag(self, name: str, key: str, value: str) -> None
| Set a tag on a prompt.
|
| This method delegates directly to the store, providing full Unity Catalog support
| when used with Unity Catalog registries.
|
| Args:
| name: Name of the prompt.
| key: Tag key.
| value: Tag value.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| client.set_prompt_tag("my_prompt", "environment", "production")
|
| set_prompt_version_tag(self, name: str, version: str | int, key: str, value: str) -> None
| Set a tag on a specific prompt version.
|
| Args:
| name: The name of the prompt.
| version: The version number of the prompt.
| key: The tag key.
| value: The tag value.
|
| set_registered_model_alias(self, name: str, alias: str, version: str) -> None
| Set a registered model alias pointing to a model version.
|
| Args:
| name: Registered model name.
| alias: Name of the alias. Note that aliases of the format ``v<number>``, such as
| ``v9`` and ``v42``, are reserved and cannot be set.
| version: Registered model version number.
|
| .. code-block:: Python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_info(rm):
| print("--Model--")
| print("name: {}".format(rm.name))
| print("aliases: {}".format(rm.aliases))
|
|
| def print_model_version_info(mv):
| print("--Model Version--")
| print("Name: {}".format(mv.name))
| print("Version: {}".format(mv.version))
| print("Aliases: {}".format(mv.aliases))
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, artifact_path="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
| model = client.get_registered_model(name)
| print_model_info(model)
|
| # Create a new version of the rfr model under the registered model name
| model_uri = "runs:/{}/sklearn-model".format(run.info.run_id)
| mv = client.create_model_version(name, model_uri, run.info.run_id)
| print_model_version_info(mv)
|
| # Set registered model alias
| client.set_registered_model_alias(name, "test-alias", mv.version)
| print()
| print_model_info(model)
| print_model_version_info(mv)
|
| .. code-block:: text
| :caption: Output
|
| --Model--
| name: RandomForestRegression
| aliases: {}
|
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: []
|
| --Model--
| name: RandomForestRegression
| aliases: {"test-alias": "1"}
|
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: ["test-alias"]
|
| set_registered_model_tag(self, name, key, value) -> None
| Set a tag for the registered model.
|
| Args:
| name: Registered model name.
| key: Tag key to log.
| value: Tag value log.
|
| .. code-block:: Python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
|
| def print_model_info(rm):
| print("--")
| print("name: {}".format(rm.name))
| print("tags: {}".format(rm.tags))
|
|
| name = "SocialMediaTextAnalyzer"
| tags = {"nlp.framework1": "Spark NLP"}
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| client = MlflowClient()
|
| # Create registered model, set an additional tag, and fetch
| # update model info
| client.create_registered_model(name, tags, desc)
| model = client.get_registered_model(name)
| print_model_info(model)
| client.set_registered_model_tag(name, "nlp.framework2", "VADER")
| model = client.get_registered_model(name)
| print_model_info(model)
|
| .. code-block:: text
| :caption: Output
|
| --
| name: SocialMediaTextAnalyzer
| tags: {'nlp.framework1': 'Spark NLP'}
| --
| name: SocialMediaTextAnalyzer
| tags: {'nlp.framework1': 'Spark NLP', 'nlp.framework2': 'VADER'}
|
| set_tag(self, run_id: str, key: str, value: Any, synchronous: bool | None = None) -> mlflow.utils.async_logging.run_operations.RunOperations | None
| Set a tag on the run with the specified ID. Value is converted to a string.
|
| Args:
| run_id: String ID of the run.
| key: Tag name. This string may only contain alphanumerics, underscores (_), dashes (-),
| periods (.), spaces ( ), and slashes (/). All backend stores will support keys up to
| length 250, but some may support larger keys.
| value: Tag value, but will be string-ified if not. All backend stores will support
| values up to length 5000, but some may support larger values.
| synchronous: *Experimental* If True, blocks until the metric is logged successfully.
| If False, logs the metric asynchronously and returns a future representing the
| logging operation. If None, read from environment variable
| `MLFLOW_ENABLE_ASYNC_LOGGING`, which defaults to False if not set.
|
| Returns:
| When `synchronous=True` or None, returns None. When `synchronous=False`, returns an
| `mlflow.utils.async_logging.run_operations.RunOperations` instance that represents
| future for logging operation.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_run_info(run):
| print(f"run_id: {run.info.run_id}")
| print(f"Tags: {run.data.tags}")
|
|
| # Create a run under the default experiment (whose id is '0').
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| print_run_info(run)
| print("--")
| # Set a tag and fetch updated run info
| client.set_tag(run.info.run_id, "nlp.framework", "Spark NLP")
| run = client.get_run(run.info.run_id)
| print_run_info(run)
|
| .. code-block:: text
| :caption: Output
|
| run_id: 4f226eb5758145e9b28f78514b59a03b
| Tags: {}
| --
| run_id: 4f226eb5758145e9b28f78514b59a03b
| Tags: {'nlp.framework': 'Spark NLP'}
|
| set_terminated(self, run_id: str, status: str | None = None, end_time: int | None = None) -> None
| Set a run's status to terminated.
|
| Args:
| run_id: The ID of the run to terminate.
| status: A string value of :py:class:`mlflow.entities.RunStatus`. Defaults to "FINISHED".
| end_time: If not provided, defaults to the current time.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
|
| def print_run_info(r):
| print(f"run_id: {r.info.run_id}")
| print(f"status: {r.info.status}")
|
|
| # Create a run under the default experiment (whose id is '0').
| # Since this is low-level CRUD operation, this method will create a run.
| # To end the run, you'll have to explicitly terminate it.
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| print_run_info(run)
| print("--")
|
| # Terminate the run and fetch updated status. By default,
| # the status is set to "FINISHED". Other values you can
| # set are "KILLED", "FAILED", "RUNNING", or "SCHEDULED".
| client.set_terminated(run.info.run_id, status="KILLED")
| run = client.get_run(run.info.run_id)
| print_run_info(run)
|
| .. code-block:: text
|
| run_id: 575fb62af83f469e84806aee24945973
| status: RUNNING
| --
| run_id: 575fb62af83f469e84806aee24945973
| status: KILLED
|
| set_trace_tag(self, trace_id: str, key: str, value: str)
| .. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
|
| Set a tag on the trace with the given trace ID.
|
| The trace can be an active one or the one that has already ended and recorded in the
| backend. Below is an example of setting a tag on an active trace. You can replace the
| ``trace_id`` parameter to set a tag on an already ended trace.
|
| .. code-block:: python
| :test:
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| root_span = client.start_trace("my_trace")
| client.set_trace_tag(root_span.trace_id, "key", "value")
| client.end_trace(root_span.trace_id)
|
| Args:
| trace_id: The ID of the trace to set the tag on.
| key: The string key of the tag. Must be at most 250 characters long, otherwise
| it will be truncated when stored.
| value: The string value of the tag. Must be at most 250 characters long, otherwise
| it will be truncated when stored.
|
| start_span(self, name: str, trace_id: str, parent_id: str, span_type: str = 'UNKNOWN', inputs: typing.Any | None = None, attributes: dict[str, typing.Any] | None = None, start_time_ns: int | None = None, links: list[mlflow.entities.link.Link] | None = None) -> mlflow.entities.span.Span
| .. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
|
| Create a new span and start it without attaching it to the global trace context.
|
| This is an imperative API to manually create a new span under a specific trace id
| and parent span, unlike the higher-level APIs like
| :py:func:`@mlflow.trace <mlflow.trace>` decorator and
| :py:func:`with mlflow.start_span() <mlflow.start_span>` context manager, which
| automatically manage the span lifecycle and parent-child relationship.
|
| This API is useful for the case where the automatic context management is not
| sufficient, such as callback-based instrumentation where span start and end are
| not in the same call stack, or multi-threaded applications where the context is
| not propagated automatically.
|
| This API requires a parent span ID to be provided explicitly. If you haven't
| started any span yet, use the :py:func:`start_trace() <start_trace>` method to
| start a new trace and a root span.
|
| .. warning::
|
| The span created with this method needs to be ended explicitly by calling
| the :py:func:`end_span() <end_span>` method. Otherwise the span will be
| recorded with the incorrect end time and status ``TRACE_STATUS_UNSPECIFIED``.
|
| .. tip::
|
| Instead of creating a root span with the :py:func:`start_trace() <start_trace>`
| method, you can also use this method within the context of a parent span created
| by the fluent APIs like :py:func:`@mlflow.trace <mlflow.trace>` and
| :py:func:`with mlflow.start_span() <mlflow.start_span>`, by passing its span
| ids the parent. This flexibility allows you to use the imperative APIs in
| conjunction with the fluent APIs like below:
|
| .. code-block:: python
| :test:
|
| import mlflow
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| with mlflow.start_span("parent_span") as parent_span:
| child_span = client.start_span(
| name="child_span",
| trace_id=parent_span.trace_id,
| parent_id=parent_span.span_id,
| )
|
| # Do something...
|
| client.end_span(
| trace_id=parent_span.trace_id,
| span_id=child_span.span_id,
| )
|
| However, **the opposite does not work**. You cannot use the fluent APIs within
| the span created by this MlflowClient API. This is because the fluent APIs
| fetches the current span from the managed context, which is not set by the MLflow
| Client APIs. Once you create a span with the MLflow Client APIs, all children
| spans must be created with the MLflow Client APIs. Please be cautious when using
| this mixed approach, as it can lead to unexpected behavior if not used properly.
|
| Args:
| name: The name of the span.
| trace_id: The ID of the trace to attach the span to. This is synonym to
| trace_id` in OpenTelemetry.
| parent_id: The ID of the parent span. The parent span can be a span created by
| both fluent APIs like `with mlflow.start_span()`, and imperative APIs like this.
| span_type: The type of the span. Can be either a string or a
| :py:class:`SpanType <mlflow.entities.SpanType>` enum value.
| inputs: Inputs to set on the span.
| attributes: A dictionary of attributes to set on the span.
| start_time_ns: The start time of the span in nano seconds since the UNIX epoch.
| If not provided, the current time will be used.
| links: A list of :py:class:`Link <mlflow.entities.Link>` objects to associate with
| the span.
|
| Returns:
| An :py:class:`mlflow.entities.Span` object representing the span.
|
| Example:
|
| .. code-block:: python
| :test:
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| span = client.start_trace("my_trace")
|
| x = 2
|
| # Create a child span
| child_span = client.start_span(
| "child_span",
| trace_id=span.trace_id,
| parent_id=span.span_id,
| inputs={"x": x},
| )
|
| y = x**2
|
| client.end_span(
| trace_id=child_span.trace_id,
| span_id=child_span.span_id,
| attributes={"factor": 2},
| outputs={"y": y},
| )
|
| client.end_trace(span.trace_id)
|
| start_trace(self, name: str, span_type: str = 'UNKNOWN', inputs: typing.Any | None = None, attributes: dict[str, str] | None = None, tags: dict[str, str] | None = None, experiment_id: str | None = None, start_time_ns: int | None = None, run_id: str | None = None, links: list[mlflow.entities.link.Link] | None = None) -> mlflow.entities.span.Span
| Create a new trace object and start a root span under it.
|
| This is an imperative API to manually create a new span under a specific trace id and
| parent span, unlike the higher-level APIs like :py:func:`@mlflow.trace <mlflow.trace>`
| and :py:func:`with mlflow.start_span() <mlflow.start_span>`, which automatically manage
| the span lifecycle and parent-child relationship. You only need to call this method
| when using the :py:func:`start_span() <start_span>` method of MlflowClient to create
| spans.
|
| .. attention::
|
| A trace started with this method must be ended by calling
| ``MlflowClient().end_trace(trace_id)``. Otherwise the trace will be not recorded.
|
| Args:
| name: The name of the trace (and the root span).
| span_type: The type of the span.
| inputs: Inputs to set on the root span of the trace.
| attributes: A dictionary of attributes to set on the root span of the trace.
| tags: A dictionary of tags to set on the trace.
| experiment_id: The ID of the experiment to create the trace in. If not provided,
| MLflow will look for valid experiment in the following order: activated using
| :py:func:`mlflow.set_experiment() <mlflow.set_experiment>`,
| ``MLFLOW_EXPERIMENT_NAME`` environment variable, ``MLFLOW_EXPERIMENT_ID``
| environment variable, or the default experiment as defined by the tracking server.
| start_time_ns: The start time of the trace in nanoseconds since the UNIX epoch.
| run_id: The ID of the MLflow run to associate with the trace. If provided, the
| trace will be linked to this run.
| links: A list of :py:class:`Link <mlflow.entities.Link>` objects to associate with
| the root span.
|
| Returns:
| An :py:class:`Span <mlflow.entities.Span>` object
| representing the root span of the trace.
|
| Example:
|
| .. code-block:: python
| :test:
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| root_span = client.start_trace("my_trace")
| trace_id = root_span.trace_id
|
| # Create a child span
| child_span = client.start_span(
| "child_span", trace_id=trace_id, parent_id=root_span.span_id
| )
| # Do something...
| client.end_span(trace_id=trace_id, span_id=child_span.span_id)
|
| client.end_trace(trace_id)
|
| test_webhook(self, webhook_id: str, event: Union[Literal['registered_model.created', 'model_version.created', 'model_version_tag.set', 'model_version_tag.deleted', 'model_version_alias.created', 'model_version_alias.deleted', 'prompt.created', 'prompt_version.created', 'prompt_tag.set', 'prompt_tag.deleted', 'prompt_version_tag.set', 'prompt_version_tag.deleted', 'prompt_alias.created', 'prompt_alias.deleted', 'budget_policy.exceeded'], mlflow.entities.webhook.WebhookEvent, NoneType] = None) -> mlflow.entities.webhook.WebhookTestResult
| Test a webhook by sending a test payload.
|
| Args:
| webhook_id: Webhook ID to test.
| event: Optional event type to test. Can be a WebhookEvent object or a string in
| "entity.action" format (e.g., "model_version.created"). If not specified, uses
| the first event from webhook.
|
| Returns:
| WebhookTestResult indicating success/failure and response details.
|
| transition_model_version_stage(self, name: str, version: str, stage: str, archive_existing_versions: bool = False) -> mlflow.entities.model_registry.model_version.ModelVersion
| .. Warning:: ``mlflow.tracking.client.MlflowClient.transition_model_version_stage`` is deprecated since 2.9.0. Model registry stages will be removed in a future major release. To learn more about the deprecation of model registry stages, see our migration guide here: https://mlflow.org/docs/latest/model-registry.html#migrating-from-stages
|
| Update model version stage.
|
| Args:
| name: Registered model name.
| version: Registered model version.
| stage: New desired stage for this model version.
| archive_existing_versions: If this flag is set to ``True``, all existing model
| versions in the stage will be automatically moved to the "archived" stage. Only
| valid when ``stage`` is ``"staging"`` or ``"production"`` otherwise an error will be
| raised.
|
| Returns:
| A single :py:class:`mlflow.entities.model_registry.ModelVersion` object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_version_info(mv):
| print(f"Name: {mv.name}")
| print(f"Version: {mv.version}")
| print(f"Description: {mv.description}")
| print(f"Stage: {mv.current_stage}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| desc = "A new version of the model using ensemble trees"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a new version of the rfr model under the registered model name
| model_uri = f"runs:/{run.info.run_id}/sklearn-model"
| mv = client.create_model_version(name, model_uri, run.info.run_id, description=desc)
| print_model_version_info(mv)
| print("--")
| # transition model version from None -> staging
| mv = client.transition_model_version_stage(name, mv.version, "staging")
| print_model_version_info(mv)
|
| .. code-block:: text
| :caption: Output
|
| Name: RandomForestRegression
| Version: 1
| Description: A new version of the model using ensemble trees
| Stage: None
| --
| Name: RandomForestRegression
| Version: 1
| Description: A new version of the model using ensemble trees
| Stage: Staging
|
| unlink_traces_from_run(self, trace_ids: list[str], run_id: str) -> None
| Unlink multiple traces from a run by removing entity associations.
|
| Args:
| trace_ids: List of trace IDs to unlink from the run.
| run_id: ID of the run to unlink traces from.
|
| Example:
| .. code-block:: python
|
| import mlflow
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Unlink multiple V4 traces from a run
| client.unlink_traces_from_run(
| trace_ids=[
| "trace://catalog.schema/abc123",
| "trace://catalog.schema/def456",
| ],
| run_id="run_abc",
| )
|
| update_mcp_access_endpoint(self, server_name: str, endpoint_id: str, url: str | None = <object object at 0x0000025F348EA210>, transport_type: mlflow.entities.mcp_server.MCPRemoteTransportType | None = <object object at 0x0000025F348EA210>, server_version: str | None = <object object at 0x0000025F348EA210>, server_alias: str | None = <object object at 0x0000025F348EA210>) -> mlflow.entities.mcp_access_endpoint.MCPAccessEndpoint
|
| update_mcp_server(self, name: str, display_name: str | None = <object object at 0x0000025F348EA210>, description: str | None = <object object at 0x0000025F348EA210>, icons: list[mlflow.store.tracking.mcp_server_registry.abstract_mixin.MCPIcon] | None = <object object at 0x0000025F348EA210>) -> mlflow.entities.mcp_server.MCPServer
|
| update_mcp_server_version(self, name: str, version: str, status: mlflow.entities.mcp_server.MCPStatus | None = <object object at 0x0000025F348EA210>, tools: list[mlflow.entities.mcp_server.MCPTool] | None = <object object at 0x0000025F348EA210>, connect_options: dict[str, mlflow.entities.mcp_server_version.ConnectOptionSettings] | None = <object object at 0x0000025F348EA210>) -> mlflow.entities.mcp_server_version.MCPServerVersion
|
| update_model_version(self, name: str, version: str, description: str | None = None) -> mlflow.entities.model_registry.model_version.ModelVersion
| Update metadata associated with a model version in backend.
|
| Args:
| name: Name of the containing registered model.
| version: Version number of the model version.
| description: New description.
|
| Returns:
| A single :py:class:`mlflow.entities.model_registry.ModelVersion` object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_version_info(mv):
| print(f"Name: {mv.name}")
| print(f"Version: {mv.version}")
| print(f"Description: {mv.description}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
| # Create a new version of the rfr model under the registered model name
| model_uri = f"runs:/{run.info.run_id}/sklearn-model"
| mv = client.create_model_version(name, model_uri, run.info.run_id)
| print_model_version_info(mv)
| print("--")
| # Update model version's description
| desc = "A new version of the model using ensemble trees"
| mv = client.update_model_version(name, mv.version, desc)
| print_model_version_info(mv)
|
| .. code-block:: text
| :caption: Output
|
| Name: RandomForestRegression
| Version: 1
| Description: None
| --
| Name: RandomForestRegression
| Version: 1
| Description: A new version of the model using ensemble trees
|
| update_registered_model(self, name: str, description: str | None = None, deployment_job_id: str | None = None) -> mlflow.entities.model_registry.registered_model.RegisteredModel
| Updates metadata for RegisteredModel entity. Input field ``description`` should be non-None.
| Backend raises exception if a registered model with given name does not exist.
|
| Args:
| name: Name of the registered model to update.
| description: (Optional) New description.
| deployment_job_id: Optional deployment job ID.
|
| Returns:
| A single updated :py:class:`mlflow.entities.model_registry.RegisteredModel` object.
|
| .. code-block:: python
| :caption: Example
|
| def print_registered_model_info(rm):
| print(f"name: {rm.name}")
| print(f"tags: {rm.tags}")
| print(f"description: {rm.description}")
|
|
| name = "SocialMediaTextAnalyzer"
| tags = {"nlp.framework": "Spark NLP"}
| desc = "This sentiment analysis model classifies the tone-happy, sad, angry."
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| client = MlflowClient()
| client.create_registered_model(name, tags, desc)
| print_registered_model_info(client.get_registered_model(name))
| print("--")
|
| # Update the model's description
| desc = "This sentiment analysis model classifies tweets' tone: happy, sad, angry."
| client.update_registered_model(name, desc)
| print_registered_model_info(client.get_registered_model(name))
|
| .. code-block:: text
| :caption: Output
|
| name: SocialMediaTextAnalyzer
| tags: {'nlp.framework': 'Spark NLP'}
| description: This sentiment analysis model classifies the tone-happy, sad, angry.
| --
| name: SocialMediaTextAnalyzer
| tags: {'nlp.framework': 'Spark NLP'}
| description: This sentiment analysis model classifies tweets' tone: happy, sad, angry.
|
| update_run(self, run_id: str, status: str | None = None, name: str | None = None) -> None
| Update a run with the specified ID to a new status or name.
|
| Args:
| run_id: The ID of the Run to update.
| status: The new status of the run to set, if specified. At least one of ``status`` or
| ``name`` should be specified.
| name: The new name of the run to set, if specified. At least one of ``name`` or
| ``status`` should be specified.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_run_info(run):
| print(f"run_id: {run.info.run_id}")
| print(f"run_name: {run.info.run_name}")
| print(f"status: {run.info.status}")
|
|
| # Create a run under the default experiment (whose id is '0').
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| print_run_info(run)
| print("--")
|
| # Update run and fetch info
| client.update_run(run.info.run_id, "FINISHED", "new_name")
| run = client.get_run(run.info.run_id)
| print_run_info(run)
|
| .. code-block:: text
| :caption: Output
|
| run_id: 1cf6bf8bf6484dd8a598bd43be367b20
| run_name: judicious-hog-915
| status: RUNNING
| --
| run_id: 1cf6bf8bf6484dd8a598bd43be367b20
| run_name: new_name
| status: FINISHED
|
| update_webhook(self, webhook_id: str, name: str | None = None, description: str | None = None, url: str | None = None, events: list[typing.Union[typing.Literal['registered_model.created', 'model_version.created', 'model_version_tag.set', 'model_version_tag.deleted', 'model_version_alias.created', 'model_version_alias.deleted', 'prompt.created', 'prompt_version.created', 'prompt_tag.set', 'prompt_tag.deleted', 'prompt_version_tag.set', 'prompt_version_tag.deleted', 'prompt_alias.created', 'prompt_alias.deleted', 'budget_policy.exceeded'], mlflow.entities.webhook.WebhookEvent]] | None = None, secret: str | None = None, status: str | mlflow.entities.webhook.WebhookStatus | None = None) -> mlflow.entities.webhook.Webhook
| Update an existing webhook.
|
| Args:
| webhook_id: Webhook ID.
| name: New webhook name.
| description: New webhook description.
| url: New webhook URL.
| events: New list of events. Can be strings or `WebhookEvent` objects.
| secret: New webhook secret.
| status: New webhook status. Can be string or WebhookStatus enum.
| Valid statuses: "ACTIVE", "DISABLED"
|
| Returns:
| A :py:class:`mlflow.entities.webhook.Webhook` object representing the updated webhook.
|
| update_workspace(self, name: str, description: str | None = None, default_artifact_root: str | None = None, trace_archival_config: mlflow.entities.workspace.TraceArchivalConfig | None = None) -> mlflow.entities.workspace.Workspace
| Update metadata for an existing workspace.
|
| Args:
| name: The name of the workspace to update.
| description: New description, or ``None`` to leave unchanged.
| default_artifact_root: New artifact root URI, empty string to clear, or ``None``.
| trace_archival_config: Optional Python-side grouping for trace archival settings.
| Use ``TraceArchivalConfig.location`` to update the archival storage URI/root and
| ``TraceArchivalConfig.retention`` to update the archived-trace retention duration
| such as ``30d`` or ``12h``. Use an empty string to clear an existing value, or
| leave fields as ``None`` to keep the current value unchanged.
|
| Returns:
| The updated workspace.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| tracking_uri
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class MlflowException(builtins.Exception)
| MlflowException(message: str, error_code: int = 1, sqlstate: str | None = None, error_class: str | None = None, **kwargs)
|
| Generic exception thrown to surface failure information about external-facing operations.
| The error message associated with this exception may be exposed to clients in HTTP responses
| for debugging purposes. If the error text is sensitive, raise a generic `Exception` object
| instead.
|
| Method resolution order:
| MlflowException
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Methods defined here:
|
| __init__(self, message: str, error_code: int = 1, sqlstate: str | None = None, error_class: str | None = None, **kwargs)
| Args:
| message: The message or exception describing the error that occurred. This will be
| included in the exception's serialized JSON representation.
| error_code: An appropriate error code for the error that occurred; it will be
| included in the exception's serialized JSON representation. This should
| be one of the codes listed in the `mlflow.protos.databricks_pb2` proto.
| sqlstate: A 5-character SQLSTATE code for error classification. If not provided,
| auto-derived from error_code.
| error_class: A descriptive error class name (e.g., "SCHEMA_ENFORCEMENT_FAILED").
| If not provided, auto-derived from error_code.
| kwargs: Additional key-value pairs to include in the serialized JSON representation
| of the MlflowException.
|
| get_http_status_code(self)
|
| serialize_as_json(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| invalid_parameter_value(message: str, sqlstate: str | None = None, error_class: str | None = None, **kwargs)
| Constructs an `MlflowException` object with the `INVALID_PARAMETER_VALUE` error code.
|
| Args:
| message: The message describing the error that occurred. This will be included in the
| exception's serialized JSON representation.
| sqlstate: A 5-character SQLSTATE code for error classification.
| error_class: A descriptive error class name.
| kwargs: Additional key-value pairs to include in the serialized JSON representation
| of the MlflowException.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
FUNCTIONS
active_run() -> mlflow.tracking.fluent.ActiveRun | None
Get the currently active ``Run``, or None if no such run exists.
.. attention::
This API is **thread-local** and returns only the active run in the current thread.
If your application is multi-threaded and a run is started in a different thread,
this API will not retrieve that run.
**Note**: You cannot access currently-active run attributes
(parameters, metrics, etc.) through the run returned by ``mlflow.active_run``. In order
to access such attributes, use the :py:class:`mlflow.client.MlflowClient` as follows:
.. code-block:: python
:test:
:caption: Example
import mlflow
mlflow.start_run()
run = mlflow.active_run()
print(f"Active run_id: {run.info.run_id}")
mlflow.end_run()
.. code-block:: text
:caption: Output
Active run_id: 6f252757005748708cd3aad75d1ff462
add_trace(trace: 'Trace | dict[str, Any]', target: 'LiveSpan | None' = None)
Add a completed trace object into another trace.
This is particularly useful when you call a remote service instrumented by
MLflow Tracing. By using this function, you can merge the trace from the remote
service into the current active local trace, so that you can see the full
trace including what happens inside the remote service call.
The following example demonstrates how to use this function to merge a trace from a remote
service to the current active trace in the function.
.. code-block:: python
@mlflow.trace(name="predict")
def predict(input):
# Call a remote service that returns a trace in the response
resp = requests.get("https://your-service-endpoint", ...)
# Extract the trace from the response
trace_json = resp.json().get("trace")
# Use the remote trace as a part of the current active trace.
# It will be merged under the span "predict" and exported together when it is ended.
mlflow.add_trace(trace_json)
If you have a specific target span to merge the trace under, you can pass the target span
.. code-block:: python
def predict(input):
# Create a local span
with mlflow.start_span(name="predict") as span:
resp = requests.get("https://your-service-endpoint", ...)
trace_json = resp.json().get("trace")
# Merge the remote trace under the span created above
mlflow.add_trace(trace_json, target=span)
Args:
trace: A :py:class:`Trace <mlflow.entities.Trace>` object or a dictionary representation
of the trace. The trace **must** be already completed i.e. no further updates should
be made to it. Otherwise, this function will raise an exception.
.. attention:
The spans in the trace must be ordered in a way that the parent span comes
before its children. If the spans are not ordered correctly, this function
will raise an exception.
target: The target span to merge the given trace.
- If provided, the trace will be merged under the target span.
- If not provided, the trace will be merged under the current active span.
- If not provided and there is no active span, a new span named "Remote Trace <...>"
will be created and the trace will be merged under it.
autolog(log_input_examples: bool = False, log_model_signatures: bool = True, log_models: bool = True, log_datasets: bool = True, log_traces: bool = True, disable: bool = False, exclusive: bool = False, disable_for_unsupported_versions: bool = False, silent: bool = False, extra_tags: dict[str, str] | None = None, exclude_flavors: list[str] | None = None) -> None
Enables (or disables) and configures autologging for all supported integrations.
The parameters are passed to any autologging integrations that support them.
See the `tracking docs <../../tracking/autolog.html>`_ for a list of supported autologging
integrations.
Note that framework-specific configurations set at any point will take precedence over
any configurations set by this function. For example:
.. code-block:: python
:test:
import mlflow
mlflow.autolog(log_models=False, exclusive=True)
import sklearn
would enable autologging for `sklearn` with `log_models=False` and `exclusive=True`,
but
.. code-block:: python
:test:
import mlflow
mlflow.autolog(log_models=False, exclusive=True)
import sklearn
mlflow.sklearn.autolog(log_models=True)
would enable autologging for `sklearn` with `log_models=True` and `exclusive=False`,
the latter resulting from the default value for `exclusive` in `mlflow.sklearn.autolog`;
other framework autolog functions (e.g. `mlflow.tensorflow.autolog`) would use the
configurations set by `mlflow.autolog` (in this instance, `log_models=False`, `exclusive=True`),
until they are explicitly called by the user.
Args:
log_input_examples: If ``True``, input examples from training datasets are collected and
logged along with model artifacts during training. If ``False``,
input examples are not logged.
Note: Input examples are MLflow model attributes
and are only collected if ``log_models`` is also ``True``.
log_model_signatures: If ``True``,
:py:class:`ModelSignatures <mlflow.models.ModelSignature>`
describing model inputs and outputs are collected and logged along
with model artifacts during training. If ``False``, signatures are
not logged. Note: Model signatures are MLflow model attributes
and are only collected if ``log_models`` is also ``True``.
log_models: If ``True``, trained models are logged as MLflow model artifacts.
If ``False``, trained models are not logged.
Input examples and model signatures, which are attributes of MLflow models,
are also omitted when ``log_models`` is ``False``.
log_datasets: If ``True``, dataset information is logged to MLflow Tracking.
If ``False``, dataset information is not logged.
log_traces: If ``True``, traces are collected for integrations.
If ``False``, no trace is collected.
disable: If ``True``, disables all supported autologging integrations. If ``False``,
enables all supported autologging integrations.
exclusive: If ``True``, autologged content is not logged to user-created fluent runs.
If ``False``, autologged content is logged to the active fluent run,
which may be user-created.
disable_for_unsupported_versions: If ``True``, disable autologging for versions of
all integration libraries that have not been tested against this version
of the MLflow client or are incompatible.
silent: If ``True``, suppress all event logs and warnings from MLflow during autologging
setup and training execution. If ``False``, show all events and warnings during
autologging setup and training execution.
extra_tags: A dictionary of extra tags to set on each managed run created by autologging.
exclude_flavors: A list of flavor names that are excluded from the auto-logging.
e.g. tensorflow, pyspark.ml
.. code-block:: python
:test:
:caption: Example
import numpy as np
import mlflow.sklearn
from mlflow import MlflowClient
from sklearn.linear_model import LinearRegression
def print_auto_logged_info(r):
tags = {k: v for k, v in r.data.tags.items() if not k.startswith("mlflow.")}
artifacts = [f.path for f in MlflowClient().list_artifacts(r.info.run_id, "model")]
print(f"run_id: {r.info.run_id}")
print(f"artifacts: {artifacts}")
print(f"params: {r.data.params}")
print(f"metrics: {r.data.metrics}")
print(f"tags: {tags}")
# prepare training data
X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]])
y = np.dot(X, np.array([1, 2])) + 3
# Auto log all the parameters, metrics, and artifacts
mlflow.autolog()
model = LinearRegression()
with mlflow.start_run() as run:
model.fit(X, y)
# fetch the auto logged parameters and metrics for ended run
print_auto_logged_info(mlflow.get_run(run_id=run.info.run_id))
.. code-block:: text
:caption: Output
run_id: fd10a17d028c47399a55ab8741721ef7
artifacts: ['model/MLmodel', 'model/conda.yaml', 'model/model.pkl']
params: {'copy_X': 'True',
'normalize': 'False',
'fit_intercept': 'True',
'n_jobs': 'None'}
metrics: {'training_score': 1.0,
'training_root_mean_squared_error': 4.440892098500626e-16,
'training_r2_score': 1.0,
'training_mean_absolute_error': 2.220446049250313e-16,
'training_mean_squared_error': 1.9721522630525295e-31}
tags: {'estimator_class': 'sklearn.linear_model._base.LinearRegression',
'estimator_name': 'LinearRegression'}
clear_active_model() -> None
Clear the active model. This will clear the active model previously set by
:py:func:`mlflow.set_active_model` or via the ``MLFLOW_ACTIVE_MODEL_ID`` environment variable
or the ``_MLFLOW_ACTIVE_MODEL_ID`` legacy environment variable.
from current thread. To temporarily switch
the active model, use ``with mlflow.set_active_model(...)`` instead.
.. code-block:: python
:test:
:caption: Example
import mlflow
# Set the active model by name
mlflow.set_active_model(name="my_model")
# Clear the active model
mlflow.clear_active_model()
# Check that the active model is None
assert mlflow.get_active_model_id() is None
# If you want to temporarily set the active model,
# use `set_active_model` as a context manager instead
with mlflow.set_active_model(name="my_model") as active_model:
assert mlflow.get_active_model_id() == active_model.model_id
assert mlflow.get_active_model_id() is None
context(metadata: 'dict[str, str] | None' = None, tags: 'dict[str, str] | None' = None, enabled: 'bool | None' = None, session_id: 'str | None' = None, user: 'str | None' = None) -> 'Generator[None, None, None]'
A context manager that injects metadata and/or tags into any trace created
within its scope, without creating a wrapper span. It can also be used to
selectively disable tracing within the scope.
This is useful when you need to attach trace-level information (e.g. session
IDs) to traces produced by code you don't control like auto-instrumented libraries,
or when you want to suppress tracing for a specific code block without affecting
the global tracing state.
.. code-block:: python
import mlflow
# Enable auto-tracing for LangChain
mlflow.langchain.autolog()
with mlflow.tracing.context(
session_id="session-123",
user="user-456",
tags={"project": "my-project"},
):
# Any trace created inside this block will carry the metadata and tags.
agent.invoke("What is the capital of France?")
# Disable tracing within a specific block
with mlflow.tracing.context(enabled=False):
# No traces will be created inside this block.
agent.invoke("This call will not be traced")
The context manager can be nested to combine multiple sets of metadata and tags. When same key
is specified in multiple levels, the value from the inner level takes precedence.
.. code-block:: python
import mlflow
with mlflow.tracing.context(metadata={"foo": "bar", "baz": "qux"}):
with mlflow.tracing.context(metadata={"foo": "baz", "qux": "quux"}):
my_func()
# Trace created by my_func will have metadata={"foo": "baz", "baz": "qux", "qux": "quux"}
Args:
metadata: Key-value pairs to inject into the trace's ``request_metadata``
(immutable after trace creation).
tags: Key-value pairs to inject into the trace's ``tags``.
enabled: Whether tracing is enabled within the scope. If ``False``, all
tracing calls within the scope will return ``NoOpSpan`` without creating
any traces. If ``None`` (default), the value is inherited from the outer
scope. This does not affect the global tracing state set by
:py:func:`mlflow.tracing.disable`.
session_id: Session ID to associate with traces created in this scope.
Internally stored as metadata under the ``mlflow.trace.session`` key.
user: User identifier to associate with traces created in this scope.
Internally stored as metadata under the ``mlflow.trace.user`` key.
create_experiment(name: str, artifact_location: str | None = None, tags: dict[str, typing.Any] | None = None, trace_location: mlflow.entities.trace_location.UnityCatalog | None = None) -> str
Create an experiment.
Args:
name: The experiment name, must be a non-empty unique string.
artifact_location: The location to store run artifacts. If not provided, the server picks
an appropriate default.
tags: An optional dictionary of string keys and values to set as tags on the experiment.
trace_location: Optional UC trace location to link to the experiment. Must be an instance
of ``mlflow.entities.trace_location.UnityCatalog(...)``. If ``table_prefix`` is not
set, it defaults to the experiment ID. Note: call ``mlflow.set_experiment`` afterward
to activate the experiment and sync the trace provider.
Returns:
String ID of the created experiment.
.. code-block:: python
:test:
:caption: Example
import mlflow
from pathlib import Path
# Create an experiment name, which must be unique and case sensitive
experiment_id = mlflow.create_experiment(
"Social NLP Experiments",
artifact_location=Path.cwd().joinpath("mlruns").as_uri(),
tags={"version": "v1", "priority": "P1"},
)
experiment = mlflow.get_experiment(experiment_id)
print(f"Name: {experiment.name}")
print(f"Experiment_id: {experiment.experiment_id}")
print(f"Artifact Location: {experiment.artifact_location}")
print(f"Tags: {experiment.tags}")
print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
print(f"Creation timestamp: {experiment.creation_time}")
.. code-block:: text
:caption: Output
Name: Social NLP Experiments
Experiment_id: 1
Artifact Location: file:///.../mlruns
Tags: {'version': 'v1', 'priority': 'P1'}
Lifecycle_stage: active
Creation timestamp: 1662004217511
create_external_model(name: str | None = None, source_run_id: str | None = None, tags: dict[str, str] | None = None, params: dict[str, str] | None = None, model_type: str | None = None, experiment_id: str | None = None) -> mlflow.entities.logged_model.LoggedModel
Create a new LoggedModel whose artifacts are stored outside of MLflow. This is useful for
tracking parameters and performance data (metrics, traces etc.) for a model, application, or
generative AI agent that is not packaged using the MLflow Model format.
Args:
name: The name of the model. If not specified, a random name will be generated.
source_run_id: The ID of the run that the model is associated with. If unspecified and a
run is active, the active run ID will be used.
tags: A dictionary of string keys and values to set as tags on the model.
params: A dictionary of string keys and values to set as parameters on the model.
model_type: The type of the model. This is a user-defined string that can be used to
search and compare related models. For example, setting ``model_type="agent"``
enables you to easily search for this model and compare it to other models of
type ``"agent"`` in the future.
experiment_id: The experiment ID of the experiment to which the model belongs.
Returns:
A new :py:class:`mlflow.entities.LoggedModel` object with status ``READY``.
create_workspace(name: 'str', description: 'str | None' = None, default_artifact_root: 'str | None' = None, trace_archival_config: 'TraceArchivalConfig | None' = None) -> 'Workspace'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Create a new workspace.
Args:
name: The workspace name (lowercase alphanumeric with optional internal hyphens).
description: Optional description of the workspace.
default_artifact_root: Optional artifact root URI; falls back to server default.
trace_archival_config: Optional archival settings; leave fields as ``None`` to omit them.
Returns:
The newly created workspace.
Raises:
MlflowException: If the name is invalid, already exists, or no artifact root available.
delete_assessment(trace_id: str, assessment_id: str)
Deletes an assessment associated with a trace.
Args:
trace_id: The ID of the trace.
assessment_id: The ID of the assessment to delete.
delete_experiment(experiment_id: str) -> None
Delete an experiment from the backend store.
Args:
experiment_id: The string-ified experiment ID returned from ``create_experiment``.
.. code-block:: python
:test:
:caption: Example
import mlflow
experiment_id = mlflow.create_experiment("New Experiment")
mlflow.delete_experiment(experiment_id)
# Examine the deleted experiment details.
experiment = mlflow.get_experiment(experiment_id)
print(f"Name: {experiment.name}")
print(f"Artifact Location: {experiment.artifact_location}")
print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
print(f"Last Updated timestamp: {experiment.last_update_time}")
.. code-block:: text
:caption: Output
Name: New Experiment
Artifact Location: file:///.../mlruns/2
Lifecycle_stage: deleted
Last Updated timestamp: 1662004217511
delete_experiment_tag(key: str) -> None
Delete a tag from the current experiment.
Args:
key: Name of the tag to be deleted.
.. code-block:: python
:test:
:caption: Example
import mlflow
exp = mlflow.set_experiment("test-delete-tag")
mlflow.set_experiment_tag("release.version", "1.0")
mlflow.delete_experiment_tag("release.version")
exp = mlflow.get_experiment(exp.experiment_id)
assert "release.version" not in exp.tags
delete_logged_model_tag(model_id: str, key: str) -> None
Delete a tag from the specified logged model.
Args:
model_id: ID of the model.
key: Tag key to delete.
Example:
.. code-block:: python
:test:
import mlflow
class DummyModel(mlflow.pyfunc.PythonModel):
def predict(self, context, model_input: list[str]) -> list[str]:
return model_input
model_info = mlflow.pyfunc.log_model(name="model", python_model=DummyModel())
mlflow.set_logged_model_tags(model_info.model_id, {"key": "value"})
model = mlflow.get_logged_model(model_info.model_id)
assert model.tags["key"] == "value"
mlflow.delete_logged_model_tag(model_info.model_id, "key")
model = mlflow.get_logged_model(model_info.model_id)
assert "key" not in model.tags
delete_prompt_alias(name: str, alias: str) -> None
Delete an alias for a :py:class:`Prompt <mlflow.entities.Prompt>` in the MLflow Prompt Registry.
Args:
name: The name of the prompt.
alias: The alias to delete for the prompt.
delete_run(run_id: str) -> None
Deletes a run with the given ID.
Args:
run_id: Unique identifier for the run to delete.
.. code-block:: python
:test:
:caption: Example
import mlflow
with mlflow.start_run() as run:
mlflow.log_param("p", 0)
run_id = run.info.run_id
mlflow.delete_run(run_id)
lifecycle_stage = mlflow.get_run(run_id).info.lifecycle_stage
print(f"run_id: {run_id}; lifecycle_stage: {lifecycle_stage}")
.. code-block:: text
:caption: Output
run_id: 45f4af3e6fd349e58579b27fcb0b8277; lifecycle_stage: deleted
delete_tag(key: str) -> None
Delete a tag from a run. This is irreversible. If no run is active, this method
will create a new active run.
Args:
key: Name of the tag
.. code-block:: python
:test:
:caption: Example
import mlflow
tags = {"engineering": "ML Platform", "engineering_remote": "ML Platform"}
with mlflow.start_run() as run:
mlflow.set_tags(tags)
with mlflow.start_run(run_id=run.info.run_id):
mlflow.delete_tag("engineering_remote")
delete_trace_tag(trace_id: 'str', key: 'str') -> 'None'
.. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
Delete a tag on the trace with the given trace ID.
The trace can be an active one or the one that has already ended and recorded in the
backend. Below is an example of deleting a tag on an active trace. You can replace the
``trace_id`` parameter to delete a tag on an already ended trace.
.. code-block:: python
:test:
import mlflow
with mlflow.start_span("my_span") as span:
mlflow.set_trace_tag(span.trace_id, "key", "value")
mlflow.delete_trace_tag(span.trace_id, "key")
Args:
trace_id: The ID of the trace to delete the tag from.
key: The string key of the tag. Must be at most 250 characters long, otherwise
it will be truncated when stored.
delete_workspace(name: 'str', *, mode: 'str' = <WorkspaceDeletionMode.RESTRICT: 'RESTRICT'>) -> 'None'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Delete an existing workspace.
Args:
name: Name of the workspace to delete.
mode: Deletion mode. One of SET_DEFAULT, CASCADE, or RESTRICT.
disable_system_metrics_logging()
Disable system metrics logging globally.
Calling this function will disable system metrics logging globally, but users can still opt in
system metrics logging for individual runs by `mlflow.start_run(log_system_metrics=True)`.
doctor(mask_envs=False)
Prints out useful information for debugging issues with MLflow.
Args:
mask_envs: If True, mask the MLflow environment variable values
(e.g. `"MLFLOW_ENV_VAR": "***"`) in the output to prevent leaking sensitive
information.
.. warning::
- This API should only be used for debugging purposes.
- The output may contain sensitive information such as a database URI containing a password.
.. code-block:: python
:caption: Example
import mlflow
with mlflow.start_run():
mlflow.doctor()
.. code-block:: text
:caption: Output
System information: Linux #58~20.04.1-Ubuntu SMP Thu Oct 13 13:09:46 UTC 2022
Python version: 3.8.13
MLflow version: 2.0.1
MLflow module location: /usr/local/lib/python3.8/site-packages/mlflow/__init__.py
Tracking URI: sqlite:///mlflow.db
Registry URI: sqlite:///mlflow.db
MLflow environment variables:
MLFLOW_TRACKING_URI: sqlite:///mlflow.db
MLflow dependencies:
Flask: 2.2.2
Jinja2: 3.0.3
alembic: 1.8.1
click: 8.1.3
cloudpickle: 2.2.0
databricks-cli: 0.17.4.dev0
docker: 6.0.0
entrypoints: 0.4
gitpython: 3.1.29
gunicorn: 20.1.0
importlib-metadata: 5.0.0
markdown: 3.4.1
matplotlib: 3.6.1
numpy: 1.23.4
packaging: 21.3
pandas: 1.5.1
protobuf: 3.19.6
pyarrow: 9.0.0
pytz: 2022.6
pyyaml: 6.0
querystring-parser: 1.2.4
requests: 2.28.1
scikit-learn: 1.1.3
scipy: 1.9.3
shap: 0.41.0
sqlalchemy: 1.4.42
sqlparse: 0.4.3
enable_system_metrics_logging()
Enable system metrics logging globally.
Calling this function will enable system metrics logging globally, but users can still opt out
system metrics logging for individual runs by `mlflow.start_run(log_system_metrics=False)`.
end_run(status: str = 'FINISHED') -> None
End an active MLflow run (if there is one).
.. code-block:: python
:test:
:caption: Example
import mlflow
# Start run and get status
mlflow.start_run()
run = mlflow.active_run()
print(f"run_id: {run.info.run_id}; status: {run.info.status}")
# End run and get status
mlflow.end_run()
run = mlflow.get_run(run.info.run_id)
print(f"run_id: {run.info.run_id}; status: {run.info.status}")
print("--")
# Check for any active runs
print(f"Active run: {mlflow.active_run()}")
.. code-block:: text
:caption: Output
run_id: b47ee4563368419880b44ad8535f6371; status: RUNNING
run_id: b47ee4563368419880b44ad8535f6371; status: FINISHED
--
Active run: None
evaluate(model=None, data=None, *, model_type=None, targets=None, predictions=None, dataset_path=None, feature_names=None, evaluators=None, evaluator_config=None, extra_metrics=None, custom_artifacts=None, env_manager='local', model_config=None, inference_params=None, model_id=None, _called_from_genai_evaluate=False)
Evaluate the model performance on given data and selected metrics.
This function evaluates a PyFunc model or custom callable on the specified dataset using
specified ``evaluators``, and logs resulting metrics & artifacts to MLflow tracking server.
Users can also skip setting ``model`` and put the model outputs in ``data`` directly for
evaluation. For detailed information, please read
`the Model Evaluation documentation <../../model-evaluation/index.html>`_.
Default Evaluator behavior:
- The default evaluator, which can be invoked with ``evaluators="default"`` or
``evaluators=None``, supports model types listed below. For each pre-defined model type, the
default evaluator evaluates your model on a selected set of metrics and generate artifacts
like plots. Please find more details below.
- For both the ``"regressor"`` and ``"classifier"`` model types, the default evaluator
generates model summary plots and feature importance plots using
`SHAP <https://shap.readthedocs.io/en/latest/index.html>`_.
- For regressor models, the default evaluator additionally logs:
- **metrics**: example_count, mean_absolute_error, mean_squared_error,
root_mean_squared_error, sum_on_target, mean_on_target, r2_score, max_error,
mean_absolute_percentage_error.
- For binary classifiers, the default evaluator additionally logs:
- **metrics**: true_negatives, false_positives, false_negatives, true_positives, recall,
precision, f1_score, accuracy_score, example_count, log_loss, roc_auc,
precision_recall_auc.
- **artifacts**: lift curve plot, precision-recall plot, ROC plot.
- For multiclass classifiers, the default evaluator additionally logs:
- **metrics**: accuracy_score, example_count, f1_score_micro, f1_score_macro, log_loss
- **artifacts**: A CSV file for "per_class_metrics" (per-class metrics includes
true_negatives/false_positives/false_negatives/true_positives/recall/precision/roc_auc,
precision_recall_auc), precision-recall merged curves plot, ROC merged curves plot.
- For question-answering models, the default evaluator logs:
- **metrics**: ``exact_match``, ``token_count``, `toxicity`_ (requires `evaluate`_,
`torch`_, `flesch_kincaid_grade_level`_ (requires `textstat`_) and `ari_grade_level`_.
- **artifacts**: A JSON file containing the inputs, outputs, targets (if the ``targets``
argument is supplied), and per-row metrics of the model in tabular format.
.. _toxicity:
https://huggingface.co/spaces/evaluate-measurement/toxicity
.. _torch:
https://pytorch.org/get-started/locally/
.. _transformers:
https://huggingface.co/docs/transformers/installation
.. _ari_grade_level:
https://en.wikipedia.org/wiki/Automated_readability_index
.. _flesch_kincaid_grade_level:
https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests#Flesch%E2%80%93Kincaid_grade_level
.. _evaluate:
https://pypi.org/project/evaluate
.. _textstat:
https://pypi.org/project/textstat
- For text-summarization models, the default evaluator logs:
- **metrics**: ``token_count``, `ROUGE`_ (requires `evaluate`_, `nltk`_, and
`rouge_score`_ to be installed), `toxicity`_ (requires `evaluate`_, `torch`_,
`transformers`_), `ari_grade_level`_ (requires `textstat`_),
`flesch_kincaid_grade_level`_ (requires `textstat`_).
- **artifacts**: A JSON file containing the inputs, outputs, targets (if the ``targets``
argument is supplied), and per-row metrics of the model in the tabular format.
.. _ROUGE:
https://huggingface.co/spaces/evaluate-metric/rouge
.. _toxicity:
https://huggingface.co/spaces/evaluate-measurement/toxicity
.. _torch:
https://pytorch.org/get-started/locally/
.. _transformers:
https://huggingface.co/docs/transformers/installation
.. _ari_grade_level:
https://en.wikipedia.org/wiki/Automated_readability_index
.. _flesch_kincaid_grade_level:
https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests#Flesch%E2%80%93Kincaid_grade_level
.. _evaluate:
https://pypi.org/project/evaluate
.. _nltk:
https://pypi.org/project/nltk
.. _rouge_score:
https://pypi.org/project/rouge-score
.. _textstat:
https://pypi.org/project/textstat
- For text models, the default evaluator logs:
- **metrics**: ``token_count``, `toxicity`_ (requires `evaluate`_, `torch`_,
`transformers`_), `ari_grade_level`_ (requires `textstat`_),
`flesch_kincaid_grade_level`_ (requires `textstat`_).
- **artifacts**: A JSON file containing the inputs, outputs, targets (if the ``targets``
argument is supplied), and per-row metrics of the model in tabular format.
.. _evaluate:
https://pypi.org/project/evaluate
.. _toxicity:
https://huggingface.co/spaces/evaluate-measurement/toxicity
.. _torch:
https://pytorch.org/get-started/locally/
.. _transformers:
https://huggingface.co/docs/transformers/installation
.. _ari_grade_level:
https://en.wikipedia.org/wiki/Automated_readability_index
.. _flesch_kincaid_grade_level:
https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests#Flesch%E2%80%93Kincaid_grade_level
.. _textstat:
https://pypi.org/project/textstat
- For retriever models, the default evaluator logs:
- **metrics**: :mod:`precision_at_k(k) <mlflow.metrics.precision_at_k>`,
:mod:`recall_at_k(k) <mlflow.metrics.recall_at_k>` and
:mod:`ndcg_at_k(k) <mlflow.metrics.ndcg_at_k>` - all have a default value of
``retriever_k`` = 3.
- **artifacts**: A JSON file containing the inputs, outputs, targets, and per-row metrics
of the model in tabular format.
- For sklearn models, the default evaluator additionally logs the model's evaluation criterion
(e.g. mean accuracy for a classifier) computed by `model.score` method.
- The metrics/artifacts listed above are logged to the active MLflow run.
If no active run exists, a new MLflow run is created for logging these metrics and
artifacts.
- Additionally, information about the specified dataset - hash, name (if specified), path
(if specified), and the UUID of the model that evaluated it - is logged to the
``mlflow.datasets`` tag.
- The available ``evaluator_config`` options for the default evaluator include:
- **log_model_explainability**: A boolean value specifying whether or not to log model
explainability insights, default value is True.
- **log_explainer**: If True, log the explainer used to compute model explainability
insights as a model. Default value is False.
- **explainability_algorithm**: A string to specify the SHAP Explainer algorithm for model
explainability. Supported algorithm includes: 'exact', 'permutation', 'partition',
'kernel'.
If not set, ``shap.Explainer`` is used with the "auto" algorithm, which chooses the best
Explainer based on the model.
- **explainability_nsamples**: The number of sample rows to use for computing model
explainability insights. Default value is 2000.
- **explainability_kernel_link**: The kernel link function used by shap kernel explainer.
Available values are "identity" and "logit". Default value is "identity".
- **max_classes_for_multiclass_roc_pr**:
For multiclass classification tasks, the maximum number of classes for which to log
the per-class ROC curve and Precision-Recall curve. If the number of classes is
larger than the configured maximum, these curves are not logged.
- **metric_prefix**: An optional prefix to prepend to the name of each metric and artifact
produced during evaluation.
- **log_metrics_with_dataset_info**: A boolean value specifying whether or not to include
information about the evaluation dataset in the name of each metric logged to MLflow
Tracking during evaluation, default value is True.
- **pos_label**: If specified, the positive label to use when computing classification
metrics such as precision, recall, f1, etc. for binary classification models. For
multiclass classification and regression models, this parameter will be ignored.
- **average**: The averaging method to use when computing classification metrics such as
precision, recall, f1, etc. for multiclass classification models
(default: ``'weighted'``). For binary classification and regression models, this
parameter will be ignored.
- **sample_weights**: Weights for each sample to apply when computing model performance
metrics.
- **col_mapping**: A dictionary mapping column names in the input dataset or output
predictions to column names used when invoking the evaluation functions.
- **retriever_k**: A parameter used when ``model_type="retriever"`` as the number of
top-ranked retrieved documents to use when computing the built-in metric
:mod:`precision_at_k(k) <mlflow.metrics.precision_at_k>`,
:mod:`recall_at_k(k) <mlflow.metrics.recall_at_k>` and
:mod:`ndcg_at_k(k) <mlflow.metrics.ndcg_at_k>`. Default value is 3. For all other
model types, this parameter will be ignored.
- Limitations of evaluation dataset:
- For classification tasks, dataset labels are used to infer the total number of classes.
- For binary classification tasks, the negative label value must be 0 or -1 or False, and
the positive label value must be 1 or True.
- Limitations of metrics/artifacts computation:
- For classification tasks, some metric and artifact computations require the model to
output class probabilities. Currently, for scikit-learn models, the default evaluator
calls the ``predict_proba`` method on the underlying model to obtain probabilities. For
other model types, the default evaluator does not compute metrics/artifacts that require
probability outputs.
- Limitations of default evaluator logging model explainability insights:
- The ``shap.Explainer`` ``auto`` algorithm uses the ``Linear`` explainer for linear models
and the ``Tree`` explainer for tree models. Because SHAP's ``Linear`` and ``Tree``
explainers do not support multi-class classification, the default evaluator falls back to
using the ``Exact`` or ``Permutation`` explainers for multi-class classification tasks.
- Logging model explainability insights is not currently supported for PySpark models.
- The evaluation dataset label values must be numeric or boolean, all feature values
must be numeric, and each feature column must only contain scalar values.
- Limitations when environment restoration is enabled:
- When environment restoration is enabled for the evaluated model (i.e. a non-local
``env_manager`` is specified), the model is loaded as a client that invokes a MLflow
Model Scoring Server process in an independent Python environment with the model's
training time dependencies installed. As such, methods like ``predict_proba`` (for
probability outputs) or ``score`` (computes the evaluation criterian for sklearn models)
of the model become inaccessible and the default evaluator does not compute metrics or
artifacts that require those methods.
- Because the model is an MLflow Model Server process, SHAP explanations are slower to
compute. As such, model explainaibility is disabled when a non-local ``env_manager``
specified, unless the ``evaluator_config`` option **log_model_explainability** is
explicitly set to ``True``.
Args:
model: Optional. If specified, it should be one of the following:
- A pyfunc model instance
- A URI referring to a pyfunc model
- A URI referring to an MLflow Deployments endpoint e.g. ``"endpoints:/my-chat"``
- A callable function: This function should be able to take in model input and
return predictions. It should follow the signature of the
:py:func:`predict <mlflow.pyfunc.PyFuncModel.predict>` method. Here's an example
of a valid function:
.. code-block:: python
model = mlflow.pyfunc.load_model(model_uri)
def fn(model_input):
return model.predict(model_input)
If omitted, it indicates a static dataset will be used for evaluation instead of a
model. In this case, the ``data`` argument must be a Pandas DataFrame or an mlflow
PandasDataset that contains model outputs, and the ``predictions`` argument must be the
name of the column in ``data`` that contains model outputs.
data: One of the
following:
- A numpy array or list of evaluation features, excluding labels.
- A Pandas DataFrame containing evaluation features, labels, and optionally model
outputs. Model outputs are required to be provided when model is unspecified.
If ``feature_names`` argument not specified, all columns except for the label
column and predictions column are regarded as feature columns. Otherwise,
only column names present in ``feature_names`` are regarded as feature columns.
- A Spark DataFrame containing evaluation features and labels. If
``feature_names`` argument not specified, all columns except for the label
column are regarded as feature columns. Otherwise, only column names present in
``feature_names`` are regarded as feature columns. Only the first 10000 rows in
the Spark DataFrame will be used as evaluation data.
- A :py:class:`mlflow.data.dataset.Dataset` instance containing evaluation
features, labels, and optionally model outputs. Model outputs are only supported
with a PandasDataset. Model outputs are required when model is unspecified, and
should be specified via the ``predictions`` property of the PandasDataset.
model_type: (Optional) A string describing the model type. The default evaluator
supports the following model types:
- ``'classifier'``
- ``'regressor'``
- ``'question-answering'``
- ``'text-summarization'``
- ``'text'``
- ``'retriever'``
If no ``model_type`` is specified, then you must provide a list of
metrics to compute via the ``extra_metrics`` param.
.. note::
``'question-answering'``, ``'text-summarization'``, ``'text'``, and
``'retriever'`` are experimental and may be changed or removed in a
future release.
targets: If ``data`` is a numpy array or list, a numpy array or list of evaluation
labels. If ``data`` is a DataFrame, the string name of a column from ``data``
that contains evaluation labels. Required for classifier and regressor models,
but optional for question-answering, text-summarization, and text models. If
``data`` is a :py:class:`mlflow.data.dataset.Dataset` that defines targets,
then ``targets`` is optional.
predictions: Optional. The name of the column that contains model outputs.
- When ``model`` is specified and outputs multiple columns, ``predictions`` can be used
to specify the name of the column that will be used to store model outputs for
evaluation.
- When ``model`` is not specified and ``data`` is a pandas dataframe,
``predictions`` can be used to specify the name of the column in ``data`` that
contains model outputs.
.. code-block:: python
:caption: Example usage of predictions
# Evaluate a model that outputs multiple columns
data = pd.DataFrame({"question": ["foo"]})
def model(inputs):
return pd.DataFrame({"answer": ["bar"], "source": ["baz"]})
results = evaluate(
model=model,
data=data,
predictions="answer",
# other arguments if needed
)
# Evaluate a static dataset
data = pd.DataFrame({"question": ["foo"], "answer": ["bar"], "source": ["baz"]})
results = evaluate(
data=data,
predictions="answer",
# other arguments if needed
)
dataset_path: (Optional) The path where the data is stored. Must not contain double
quotes (``"``). If specified, the path is logged to the ``mlflow.datasets``
tag for lineage tracking purposes.
feature_names: (Optional) A list. If the ``data`` argument is a numpy array or list,
``feature_names`` is a list of the feature names for each feature. If
``feature_names=None``, then the ``feature_names`` are generated using the
format ``feature_{feature_index}``. If the ``data`` argument is a Pandas
DataFrame or a Spark DataFrame, ``feature_names`` is a list of the names
of the feature columns in the DataFrame. If ``feature_names=None``, then
all columns except the label column and the predictions column are
regarded as feature columns.
evaluators: The name of the evaluator to use for model evaluation, or a list of
evaluator names. If unspecified, all evaluators capable of evaluating the
specified model on the specified dataset are used. The default evaluator
can be referred to by the name ``"default"``. To see all available
evaluators, call :py:func:`mlflow.models.list_evaluators`.
evaluator_config: A dictionary of additional configurations to supply to the evaluator.
If multiple evaluators are specified, each configuration should be
supplied as a nested dictionary whose key is the evaluator name.
extra_metrics:
(Optional) A list of :py:class:`EvaluationMetric <mlflow.models.EvaluationMetric>`
objects. These metrics are computed in addition to the default metrics associated with
pre-defined `model_type`, and setting `model_type=None` will only compute the metrics
specified in `extra_metrics`. See the `mlflow.metrics` module for more information about
the builtin metrics and how to define extra metrics.
.. code-block:: python
:caption: Example usage of extra metrics
import mlflow
import numpy as np
def root_mean_squared_error(eval_df, _builtin_metrics):
return np.sqrt((np.abs(eval_df["prediction"] - eval_df["target"]) ** 2).mean())
rmse_metric = mlflow.models.make_metric(
eval_fn=root_mean_squared_error,
greater_is_better=False,
)
mlflow.evaluate(..., extra_metrics=[rmse_metric])
custom_artifacts:
(Optional) A list of custom artifact functions with the following signature:
.. code-block:: python
def custom_artifact(
eval_df: Union[pandas.Dataframe, pyspark.sql.DataFrame],
builtin_metrics: Dict[str, float],
artifacts_dir: str,
) -> Dict[str, Any]:
"""
Args:
eval_df:
A Pandas or Spark DataFrame containing ``prediction`` and ``target``
column. The ``prediction`` column contains the predictions made by the
model. The ``target`` column contains the corresponding labels to the
predictions made on that row.
builtin_metrics:
A dictionary containing the metrics calculated by the default evaluator.
The keys are the names of the metrics and the values are the scalar
values of the metrics. Refer to the DefaultEvaluator behavior section
for what metrics will be returned based on the type of model (i.e.
classifier or regressor).
artifacts_dir:
A temporary directory path that can be used by the custom artifacts
function to temporarily store produced artifacts. The directory will be
deleted after the artifacts are logged.
Returns:
A dictionary that maps artifact names to artifact objects
(e.g. a Matplotlib Figure) or to artifact paths within ``artifacts_dir``.
"""
...
Object types that artifacts can be represented as:
- A string uri representing the file path to the artifact. MLflow will infer the
type of the artifact based on the file extension.
- A string representation of a JSON object. This will be saved as a .json artifact.
- Pandas DataFrame. This will be resolved as a CSV artifact.
- Numpy array. This will be saved as a .npy artifact.
- Matplotlib Figure. This will be saved as an image artifact. Note that
``matplotlib.pyplot.savefig`` is called behind the scene with default
configurations.
To customize, either save the figure with the desired configurations and return
its file path or define customizations through environment variables in
``matplotlib.rcParams``.
- Other objects will be attempted to be pickled with the default protocol.
.. code-block:: python
:caption: Example usage of custom artifacts
import mlflow
import matplotlib.pyplot as plt
def scatter_plot(eval_df, builtin_metrics, artifacts_dir):
plt.scatter(eval_df["prediction"], eval_df["target"])
plt.xlabel("Targets")
plt.ylabel("Predictions")
plt.title("Targets vs. Predictions")
plt.savefig(os.path.join(artifacts_dir, "example.png"))
plt.close()
return {"pred_target_scatter": os.path.join(artifacts_dir, "example.png")}
def pred_sample(eval_df, _builtin_metrics, _artifacts_dir):
return {"pred_sample": pred_sample.head(10)}
mlflow.evaluate(..., custom_artifacts=[scatter_plot, pred_sample])
env_manager: Specify an environment manager to load the candidate ``model`` in
isolated Python environments and restore their
dependencies. Default value is ``local``, and the following values are
supported:
- ``virtualenv``: (Recommended) Use virtualenv to restore the python
environment that was used to train the model.
- ``conda``: Use Conda to restore the software environment that was used
to train the model.
- ``local``: Use the current Python environment for model inference, which
may differ from the environment used to train the model and may lead to
errors or invalid predictions.
model_config: the model configuration to use for loading the model with pyfunc. Inspect
the model's pyfunc flavor to know which keys are supported for your
specific model. If not indicated, the default model configuration
from the model is used (if any).
inference_params: (Optional) A dictionary of inference parameters to be passed to the model
when making predictions, such as ``{"max_tokens": 100}``. This is only used when
the ``model`` is an MLflow Deployments endpoint URI e.g. ``"endpoints:/my-chat"``
model_id: (Optional) The ID of the MLflow LoggedModel or Model Version to which the
evaluation results (e.g. metrics and traces) will be linked. If `model_id` is not
specified but `model` is specified, the ID from `model` will be used.
_called_from_genai_evaluate: (Optional) Only used internally.
Returns:
An :py:class:`mlflow.models.EvaluationResult` instance containing
metrics of evaluating the model with the given dataset.
finalize_logged_model(model_id: str, status: Union[Literal['READY', 'FAILED'], mlflow.entities.logged_model_status.LoggedModelStatus]) -> mlflow.entities.logged_model.LoggedModel
Finalize a model by updating its status.
Args:
model_id: ID of the model to finalize.
status: Final status to set on the model.
Returns:
The updated model.
Example:
.. code-block:: python
:test:
import mlflow
from mlflow.entities import LoggedModelStatus
model = mlflow.initialize_logged_model(name="model")
logged_model = mlflow.finalize_logged_model(
model_id=model.model_id,
status=LoggedModelStatus.READY,
)
assert logged_model.status == LoggedModelStatus.READY
flush_artifact_async_logging() -> None
Flush all pending artifact async logging.
flush_async_logging() -> None
Flush all pending async logging.
flush_trace_async_logging(terminate=False) -> None
Flush all pending trace async logging.
Args:
terminate: If True, shut down the logging threads after flushing.
get_active_model_id() -> str | None
Get the active model ID. If no active model is set with ``set_active_model()``, the
default active model is set using model ID from the environment variable
``MLFLOW_ACTIVE_MODEL_ID`` or the legacy environment variable ``_MLFLOW_ACTIVE_MODEL_ID``.
If neither is set, return None. Note that this function only get the active model ID from the
current thread.
Returns:
The active model ID if set, otherwise None.
get_active_trace_id() -> 'str | None'
Get the active trace ID in the current process.
This function is thread-safe.
Example:
.. code-block:: python
:test:
import mlflow
@mlflow.trace
def f():
trace_id = mlflow.get_active_trace_id()
print(trace_id)
f()
Returns:
The ID of the current active trace if exists, otherwise None.
get_artifact_uri(artifact_path: str | None = None) -> str
Get the absolute URI of the specified artifact in the currently active run.
If `path` is not specified, the artifact root URI of the currently active
run will be returned; calls to ``log_artifact`` and ``log_artifacts`` write
artifact(s) to subdirectories of the artifact root URI.
If no run is active, this method will create a new active run.
Args:
artifact_path: The run-relative artifact path for which to obtain an absolute URI.
For example, "path/to/artifact". If unspecified, the artifact root URI
for the currently active run will be returned.
Returns:
An *absolute* URI referring to the specified artifact or the currently active run's
artifact root. For example, if an artifact path is provided and the currently active
run uses an S3-backed store, this may be a uri of the form
``s3://<bucket_name>/path/to/artifact/root/path/to/artifact``. If an artifact path
is not provided and the currently active run uses an S3-backed store, this may be a
URI of the form ``s3://<bucket_name>/path/to/artifact/root``.
.. code-block:: python
:test:
:caption: Example
import tempfile
import mlflow
features = "rooms, zipcode, median_price, school_rating, transport"
with tempfile.NamedTemporaryFile("w") as tmp_file:
tmp_file.write(features)
tmp_file.flush()
# Log the artifact in a directory "features" under the root artifact_uri/features
with mlflow.start_run():
mlflow.log_artifact(tmp_file.name, artifact_path="features")
# Fetch the artifact uri root directory
artifact_uri = mlflow.get_artifact_uri()
print(f"Artifact uri: {artifact_uri}")
# Fetch a specific artifact uri
artifact_uri = mlflow.get_artifact_uri(artifact_path="features/features.txt")
print(f"Artifact uri: {artifact_uri}")
.. code-block:: text
:caption: Output
Artifact uri: file:///.../0/a46a80f1c9644bd8f4e5dd5553fffce/artifacts
Artifact uri: file:///.../0/a46a80f1c9644bd8f4e5dd5553fffce/artifacts/features/features.txt
get_assessment(trace_id: str, assessment_id: str) -> mlflow.entities.assessment.Assessment
Get an assessment entity from the backend store.
Args:
trace_id: The ID of the trace.
assessment_id: The ID of the assessment to get.
Returns:
:py:class:`~mlflow.entities.Assessment`: The Assessment object.
get_current_active_span() -> 'LiveSpan | None'
Get the current active span in the global context.
.. attention::
This only works when the span is created with fluent APIs like `@mlflow.trace` or
`with mlflow.start_span`. If a span is created with the
`mlflow.start_span_no_context` APIs, it won't be
attached to the global context so this function will not return it.
.. code-block:: python
:test:
import mlflow
@mlflow.trace
def f():
span = mlflow.get_current_active_span()
span.set_attribute("key", "value")
return 0
f()
Returns:
The current active span if exists, otherwise None.
get_experiment(experiment_id: str) -> mlflow.entities.experiment.Experiment
Retrieve an experiment by experiment_id from the backend store
Args:
experiment_id: The string-ified experiment ID returned from ``create_experiment``.
Returns:
:py:class:`mlflow.entities.Experiment`
.. code-block:: python
:test:
:caption: Example
import mlflow
experiment = mlflow.get_experiment("0")
print(f"Name: {experiment.name}")
print(f"Artifact Location: {experiment.artifact_location}")
print(f"Tags: {experiment.tags}")
print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
print(f"Creation timestamp: {experiment.creation_time}")
.. code-block:: text
:caption: Output
Name: Default
Artifact Location: file:///.../mlruns/0
Tags: {}
Lifecycle_stage: active
Creation timestamp: 1662004217511
get_experiment_by_name(name: str) -> mlflow.entities.experiment.Experiment | None
Retrieve an experiment by experiment name from the backend store
Args:
name: The case sensitive experiment name.
Returns:
An instance of :py:class:`mlflow.entities.Experiment`
if an experiment with the specified name exists, otherwise None.
.. code-block:: python
:test:
:caption: Example
import mlflow
# Case sensitive name
experiment = mlflow.get_experiment_by_name("Default")
print(f"Experiment_id: {experiment.experiment_id}")
print(f"Artifact Location: {experiment.artifact_location}")
print(f"Tags: {experiment.tags}")
print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
print(f"Creation timestamp: {experiment.creation_time}")
.. code-block:: text
:caption: Output
Experiment_id: 0
Artifact Location: file:///.../mlruns/0
Tags: {}
Lifecycle_stage: active
Creation timestamp: 1662004217511
get_last_active_trace_id(thread_local: 'bool' = False) -> 'str | None'
Get the **LAST** active trace in the same process if exists.
.. warning::
This function is not thread-safe by default, returns the last active trace in
the same process. If you want to get the last active trace in the current thread,
set the `thread_local` parameter to True.
Args:
thread_local: If True, returns the last active trace in the current thread. Otherwise,
returns the last active trace in the same process. Default is False.
Returns:
The ID of the last active trace if exists, otherwise None.
.. code-block:: python
:test:
import mlflow
@mlflow.trace
def f():
pass
f()
trace_id = mlflow.get_last_active_trace_id()
# Set a tag on the trace
mlflow.set_trace_tag(trace_id, "key", "value")
# Get the full trace object
trace = mlflow.get_trace(trace_id)
get_logged_model(model_id: str) -> mlflow.entities.logged_model.LoggedModel
Get a logged model by ID.
Args:
model_id: The ID of the logged model.
Returns:
The logged model.
Example:
.. code-block:: python
:test:
import mlflow
class DummyModel(mlflow.pyfunc.PythonModel):
def predict(self, context, model_input: list[str]) -> list[str]:
return model_input
model_info = mlflow.pyfunc.log_model(name="model", python_model=DummyModel())
logged_model = mlflow.get_logged_model(model_id=model_info.model_id)
assert logged_model.model_id == model_info.model_id
get_parent_run(run_id: str) -> mlflow.entities.run.Run | None
Gets the parent run for the given run id if one exists.
Args:
run_id: Unique identifier for the child run.
Returns:
A single :py:class:`mlflow.entities.Run` object, if the parent run exists. Otherwise,
returns None.
.. code-block:: python
:test:
:caption: Example
import mlflow
# Create nested runs
with mlflow.start_run():
with mlflow.start_run(nested=True) as child_run:
child_run_id = child_run.info.run_id
parent_run = mlflow.get_parent_run(child_run_id)
print(f"child_run_id: {child_run_id}")
print(f"parent_run_id: {parent_run.info.run_id}")
.. code-block:: text
:caption: Output
child_run_id: 7d175204675e40328e46d9a6a5a7ee6a
parent_run_id: 8979459433a24a52ab3be87a229a9cdf
get_registry_uri() -> str
Get the current registry URI. If none has been specified, defaults to the tracking URI.
Returns:
The registry URI.
.. code-block:: python
# Get the current model registry uri
mr_uri = mlflow.get_registry_uri()
print(f"Current model registry uri: {mr_uri}")
# Get the current tracking uri
tracking_uri = mlflow.get_tracking_uri()
print(f"Current tracking uri: {tracking_uri}")
# They should be the same
assert mr_uri == tracking_uri
.. code-block:: text
Current model registry uri: file:///.../mlruns
Current tracking uri: file:///.../mlruns
get_run(run_id: str) -> mlflow.entities.run.Run
Fetch the run from backend store. The resulting Run contains a collection of run metadata --
RunInfo as well as a collection of run parameters, tags, and metrics -- RunData. It also
contains a collection of run inputs (experimental), including information about datasets used by
the run -- RunInputs. In the case where multiple metrics with the same key are logged for the
run, the RunData contains the most recently logged value at the largest step for each metric.
Args:
run_id: Unique identifier for the run.
Returns:
A single Run object, if the run exists. Otherwise, raises an exception.
.. code-block:: python
:test:
:caption: Example
import mlflow
with mlflow.start_run() as run:
mlflow.log_param("p", 0)
run_id = run.info.run_id
print(f"run_id: {run_id}; lifecycle_stage: {mlflow.get_run(run_id).info.lifecycle_stage}")
.. code-block:: text
:caption: Output
run_id: 7472befefc754e388e8e922824a0cca5; lifecycle_stage: active
get_trace(trace_id: 'str', silent: 'bool' = False, flush: 'bool' = False) -> 'Trace | None'
.. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
Get a trace by the given request ID if it exists.
This function retrieves the trace from the in-memory buffer first, and if it doesn't exist,
it fetches the trace from the tracking store. If the trace is not found in the tracking store,
it returns None.
Args:
trace_id: The ID of the trace.
silent: If True, suppress the warning message when the trace is not found. The API will
return None without any warning. Default to False.
flush: If True and the trace is not found, flush any pending async trace writes and
retry. Useful in tests or scripts where async logging may not have completed.
Default to False.
.. code-block:: python
:test:
import mlflow
with mlflow.start_span(name="span") as span:
span.set_attribute("key", "value")
trace = mlflow.get_trace(span.trace_id)
print(trace)
Returns:
A :py:class:`mlflow.entities.Trace` objects with the given request ID.
get_tracking_uri() -> str
Get the current tracking URI. This may not correspond to the tracking URI of
the currently active run, since the tracking URI can be updated via ``set_tracking_uri``.
Returns:
The tracking URI.
.. code-block:: python
import mlflow
# Get the current tracking uri
tracking_uri = mlflow.get_tracking_uri()
print(f"Current tracking uri: {tracking_uri}")
.. code-block:: text
Current tracking uri: sqlite:///mlflow.db
get_workspace(name: 'str') -> 'Workspace'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Return metadata for the specified workspace.
import_checkpoints(checkpoint_path: str, source_run_id: str | None = None, model_prefix: str | None = None, overwrite_checkpoints: bool = False) -> list[mlflow.entities.logged_model.LoggedModel]
Create external models for all top-level files and directories under the specified
checkpoint path.
This API only supports Databricks runtime currently.
Args:
checkpoint_path: Path that contains the checkpoints.
Only Databricks Unity Catalog Volume path is supported for now.
It must follows the
"/Volumes/<catalog_identifier>/<schema_identifier>/<volume_identifier>/<path_to_checkpoints_directory>"
format specified https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-volumes#volume-naming-and-reference.
Note: Each path must be isolated from other models and runs.
source_run_id: ID of the MLflow source run that these checkpoints were trained with.
If not provided, uses the current active run if available.
model_prefix: String prefix to prepend to the name of each external model created from
each checkpoint. If not provided, no prefix is applied.
overwrite_checkpoints: If True and existing models are found with the same name in the
associated experiment, they will be deleted and recreated to point to the latest
checkpoint. Defaults to False.
Returns:
List of imported models. If 'overwrite_checkpoints' is True, the list only contains
new created models, otherwise the list contains new created models for the new model
names and existing models for the existing model names.
Example:
.. code-block:: python
import mlflow
# Optionally start a run so `source_run_id` can be inferred
with mlflow.start_run() as run:
# ... training code that writes checkpoints to a UC Volume ...
logged_models = mlflow.import_checkpoints(
checkpoint_path=(
"/Volumes/mycatalog/myschema/myvolume/mytrainingmodel/trainingrun1/checkpoints"
),
# You can omit `source_run_id` if there is an active run.
# source_run_id=run.info.run_id,
model_prefix="my_model_",
overwrite_checkpoints=True,
)
initialize_logged_model(name: str | None = None, source_run_id: str | None = None, tags: dict[str, str] | None = None, params: dict[str, str] | None = None, model_type: str | None = None, experiment_id: str | None = None) -> mlflow.entities.logged_model.LoggedModel
Initialize a LoggedModel. Creates a LoggedModel with status ``PENDING`` and no artifacts. You
must add artifacts to the model and finalize it to the ``READY`` state, for example by calling
a flavor-specific ``log_model()`` method such as :py:func:`mlflow.pyfunc.log_model()`.
Args:
name: The name of the model. If not specified, a random name will be generated.
source_run_id: The ID of the run that the model is associated with. If unspecified and a
run is active, the active run ID will be used.
tags: A dictionary of string keys and values to set as tags on the model.
params: A dictionary of string keys and values to set as parameters on the model.
model_type: The type of the model.
experiment_id: The experiment ID of the experiment to which the model belongs.
Returns:
A new :py:class:`mlflow.entities.LoggedModel` object with status ``PENDING``.
is_tracking_uri_set()
Returns True if the tracking URI has been set, False otherwise.
last_active_run() -> mlflow.entities.run.Run | None
Gets the most recent active run.
Examples:
.. code-block:: python
:test:
:caption: To retrieve the most recent autologged run:
import mlflow
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_diabetes
from sklearn.ensemble import RandomForestRegressor
mlflow.autolog()
db = load_diabetes()
X_train, X_test, y_train, y_test = train_test_split(db.data, db.target)
# Create and train models.
rf = RandomForestRegressor(n_estimators=100, max_depth=6, max_features=3)
rf.fit(X_train, y_train)
# Use the model to make predictions on the test dataset.
predictions = rf.predict(X_test)
autolog_run = mlflow.last_active_run()
.. code-block:: python
:test:
:caption: To get the most recently active run that ended:
import mlflow
mlflow.start_run()
mlflow.end_run()
run = mlflow.last_active_run()
.. code-block:: python
:test:
:caption: To retrieve the currently active run:
import mlflow
mlflow.start_run()
run = mlflow.last_active_run()
mlflow.end_run()
Returns:
The active run (this is equivalent to ``mlflow.active_run()``) if one exists.
Otherwise, the last run started from the current Python process that reached
a terminal status (i.e. FINISHED, FAILED, or KILLED).
last_logged_model() -> mlflow.entities.logged_model.LoggedModel | None
Fetches the most recent logged model in the current session.
If no model has been logged, None is returned.
Returns:
The logged model.
.. code-block:: python
:test:
:caption: Example
import mlflow
class DummyModel(mlflow.pyfunc.PythonModel):
def predict(self, context, model_input: list[str]) -> list[str]:
return model_input
model_info = mlflow.pyfunc.log_model(name="model", python_model=DummyModel())
last_model = mlflow.last_logged_model()
assert last_model.model_id == model_info.model_id
list_workspaces() -> 'list[Workspace]'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Return the list of workspaces available to the current user.
load_prompt(name_or_uri: str, version: str | int | None = None, allow_missing: bool = False, link_to_model: bool = True, model_id: str | None = None, cache_ttl_seconds: float | None = None) -> mlflow.entities.model_registry.prompt_version.PromptVersion
Load a :py:class:`Prompt <mlflow.entities.Prompt>` from the MLflow Prompt Registry.
The prompt can be specified by name and version, or by URI.
Args:
name_or_uri: The name of the prompt, or the URI in the format "prompts:/name/version".
version: The version of the prompt (required when using name, not allowed when using URI).
allow_missing: If True, return None instead of raising Exception if the specified prompt
is not found.
link_to_model: If True, the prompt will be linked to the model with the ID specified
by `model_id`, or the active model ID if `model_id` is None and
there is an active model.
model_id: The ID of the model to which to link the prompt, if `link_to_model` is True.
cache_ttl_seconds: Time-to-live in seconds for the cached prompt. If not specified,
uses the value from `MLFLOW_ALIAS_PROMPT_CACHE_TTL_SECONDS` environment variable for
alias-based prompts (default 60), and the value from
`MLFLOW_VERSION_PROMPT_CACHE_TTL_SECONDS` environment variable for version-based prompts
(default None, no TTL). Set to 0 to bypass the cache and always fetch from the server.
Example:
.. code-block:: python
import mlflow
# Load a specific version of the prompt
prompt = mlflow.load_prompt("my_prompt", version=1)
# Load a specific version of the prompt by URI
prompt = mlflow.load_prompt("prompts:/my_prompt/1")
# Load a prompt version with an alias "production"
prompt = mlflow.load_prompt("prompts:/my_prompt@production")
# Load with custom cache TTL (5 minutes)
prompt = mlflow.load_prompt("my_prompt", version=1, cache_ttl_seconds=300)
# Bypass cache entirely
prompt = mlflow.load_prompt("my_prompt", version=1, cache_ttl_seconds=0)
load_table(artifact_file: str, run_ids: list[str] | None = None, extra_columns: list[str] | None = None) -> 'pandas.DataFrame'
Load a table from MLflow Tracking as a pandas.DataFrame. The table is loaded from the
specified artifact_file in the specified run_ids. The extra_columns are columns that
are not in the table but are augmented with run information and added to the DataFrame.
Args:
artifact_file: The run-relative artifact file path in posixpath format to which
table to load (e.g. "dir/file.json").
run_ids: Optional list of run_ids to load the table from. If no run_ids are specified,
the table is loaded from all runs in the current experiment.
extra_columns: Optional list of extra columns to add to the returned DataFrame
For example, if extra_columns=["run_id"], then the returned DataFrame
will have a column named run_id.
Returns:
pandas.DataFrame containing the loaded table if the artifact exists
or else throw a MlflowException.
.. code-block:: python
:test:
:caption: Example with passing run_ids
import mlflow
table_dict = {
"inputs": ["What is MLflow?", "What is Databricks?"],
"outputs": ["MLflow is ...", "Databricks is ..."],
"toxicity": [0.0, 0.0],
}
with mlflow.start_run() as run:
# Log the dictionary as a table
mlflow.log_table(data=table_dict, artifact_file="qabot_eval_results.json")
run_id = run.info.run_id
loaded_table = mlflow.load_table(
artifact_file="qabot_eval_results.json",
run_ids=[run_id],
# Append a column containing the associated run ID for each row
extra_columns=["run_id"],
)
.. code-block:: python
:test:
:caption: Example with passing no run_ids
# Loads the table with the specified name for all runs in the given
# experiment and joins them together
import mlflow
table_dict = {
"inputs": ["What is MLflow?", "What is Databricks?"],
"outputs": ["MLflow is ...", "Databricks is ..."],
"toxicity": [0.0, 0.0],
}
with mlflow.start_run():
# Log the dictionary as a table
mlflow.log_table(data=table_dict, artifact_file="qabot_eval_results.json")
loaded_table = mlflow.load_table(
"qabot_eval_results.json",
# Append the run ID and the parent run ID to the table
extra_columns=["run_id"],
)
log_artifact(local_path: str, artifact_path: str | None = None, run_id: str | None = None) -> None
Log a local file or directory as an artifact of the currently active run. If no run is
active, this method will create a new active run.
Args:
local_path: Path to the file to write.
artifact_path: If provided, the directory in ``artifact_uri`` to write to.
run_id: If specified, log the artifact to the specified run. If not specified, log the
artifact to the currently active run.
.. code-block:: python
:test:
:caption: Example
import tempfile
from pathlib import Path
import mlflow
# Create a features.txt artifact file
features = "rooms, zipcode, median_price, school_rating, transport"
with tempfile.TemporaryDirectory() as tmp_dir:
path = Path(tmp_dir, "features.txt")
path.write_text(features)
# With artifact_path=None write features.txt under
# root artifact_uri/artifacts directory
with mlflow.start_run():
mlflow.log_artifact(path)
log_artifacts(local_dir: str, artifact_path: str | None = None, run_id: str | None = None) -> None
Log all the contents of a local directory as artifacts of the run. If no run is active,
this method will create a new active run.
Args:
local_dir: Path to the directory of files to write.
artifact_path: If provided, the directory in ``artifact_uri`` to write to.
run_id: If specified, log the artifacts to the specified run. If not specified, log the
artifacts to the currently active run.
.. code-block:: python
:test:
:caption: Example
import json
import tempfile
from pathlib import Path
import mlflow
# Create some files to preserve as artifacts
features = "rooms, zipcode, median_price, school_rating, transport"
data = {"state": "TX", "Available": 25, "Type": "Detached"}
with tempfile.TemporaryDirectory() as tmp_dir:
tmp_dir = Path(tmp_dir)
with (tmp_dir / "data.json").open("w") as f:
json.dump(data, f, indent=2)
with (tmp_dir / "features.json").open("w") as f:
f.write(features)
# Write all files in `tmp_dir` to root artifact_uri/states
with mlflow.start_run():
mlflow.log_artifacts(tmp_dir, artifact_path="states")
log_assessment(trace_id: str, assessment: mlflow.entities.assessment.Assessment) -> mlflow.entities.assessment.Assessment
Logs an assessment to a Trace. The assessment can be an expectation or a feedback.
- Expectation: A label that represents the expected value for a particular operation.
For example, an expected answer for a user question from a chatbot.
- Feedback: A label that represents the feedback on the quality of the operation.
Feedback can come from different sources, such as human judges, heuristic scorers,
or LLM-as-a-Judge.
The following code annotates a trace with a feedback provided by LLM-as-a-Judge.
.. code-block:: python
import mlflow
from mlflow.entities import Feedback
feedback = Feedback(
name="faithfulness",
value=0.9,
rationale="The model is faithful to the input.",
metadata={"model": "gpt-4o-mini"},
)
mlflow.log_assessment(trace_id="1234", assessment=feedback)
The following code annotates a trace with human-provided ground truth with source information.
When the source is not provided, the default source is set to "default" with type "HUMAN"
.. code-block:: python
import mlflow
from mlflow.entities import AssessmentSource, AssessmentSourceType, Expectation
# Specify the annotator information as a source.
source = AssessmentSource(
source_type=AssessmentSourceType.HUMAN,
source_id="john@example.com",
)
expectation = Expectation(
name="expected_answer",
value=42,
source=source,
)
mlflow.log_assessment(trace_id="1234", assessment=expectation)
The expectation value can be any JSON-serializable value. For example, you may
record the full LLM message as the expectation value.
.. code-block:: python
import mlflow
from mlflow.entities.assessment import Expectation
expectation = Expectation(
name="expected_message",
# Full LLM message including expected tool calls
value={
"role": "assistant",
"content": "The answer is 42.",
"tool_calls": [
{
"id": "1234",
"type": "function",
"function": {"name": "add", "arguments": "40 + 2"},
}
],
},
)
mlflow.log_assessment(trace_id="1234", assessment=expectation)
You can also log an error information during the feedback generation process. To do so,
provide an instance of :py:class:`~mlflow.entities.AssessmentError` to the `error`
parameter, and leave the `value` parameter as `None`.
.. code-block:: python
import mlflow
from mlflow.entities import AssessmentError, Feedback
error = AssessmentError(
error_code="RATE_LIMIT_EXCEEDED",
error_message="Rate limit for the judge exceeded.",
)
feedback = Feedback(
trace_id="1234",
name="faithfulness",
error=error,
)
mlflow.log_assessment(trace_id="1234", assessment=feedback)
log_dict(dictionary: dict[str, typing.Any], artifact_file: str, run_id: str | None = None) -> None
Log a JSON/YAML-serializable object (e.g. `dict`) as an artifact. The serialization
format (JSON or YAML) is automatically inferred from the extension of `artifact_file`.
If the file extension doesn't exist or match any of [".json", ".yml", ".yaml"],
JSON format is used.
Args:
dictionary: Dictionary to log.
artifact_file: The run-relative artifact file path in posixpath format to which
the dictionary is saved (e.g. "dir/data.json").
run_id: If specified, log the dictionary to the specified run. If not specified, log the
dictionary to the currently active run.
.. code-block:: python
:test:
:caption: Example
import mlflow
dictionary = {"k": "v"}
with mlflow.start_run():
# Log a dictionary as a JSON file under the run's root artifact directory
mlflow.log_dict(dictionary, "data.json")
# Log a dictionary as a YAML file in a subdirectory of the run's root artifact directory
mlflow.log_dict(dictionary, "dir/data.yml")
# If the file extension doesn't exist or match any of [".json", ".yaml", ".yml"],
# JSON format is used.
mlflow.log_dict(dictionary, "data")
mlflow.log_dict(dictionary, "data.txt")
log_expectation(*, trace_id: str, name: str, value: Any, source: mlflow.entities.assessment_source.AssessmentSource | None = None, metadata: dict[str, typing.Any] | None = None, span_id: str | None = None) -> mlflow.entities.assessment.Assessment
Logs an expectation (e.g. ground truth label) to a Trace. This API only takes keyword arguments.
Args:
trace_id: The ID of the trace.
name: The name of the expectation assessment e.g., "expected_answer
value: The value of the expectation. It can be any JSON-serializable value.
source: The source of the expectation assessment. Must be an instance of
:py:class:`~mlflow.entities.AssessmentSource`. If not provided,
default to HUMAN source type.
metadata: Additional metadata for the expectation.
span_id: The ID of the span associated with the expectation, if it needs be
associated with a specific span in the trace.
Returns:
:py:class:`~mlflow.entities.Assessment`: The created expectation assessment.
Examples:
.. code-block:: python
import mlflow
from mlflow.entities import AssessmentSource, AssessmentSourceType
# Log simple expected answer
expectation = mlflow.log_expectation(
trace_id="tr-1234567890abcdef",
name="expected_answer",
value="The capital of France is Paris.",
source=AssessmentSource(
source_type=AssessmentSourceType.HUMAN, source_id="annotator@company.com"
),
metadata={"question_type": "factual", "difficulty": "easy"},
)
# Log expected classification label
mlflow.log_expectation(
trace_id="tr-1234567890abcdef",
name="expected_category",
value="positive",
source=AssessmentSource(
source_type=AssessmentSourceType.HUMAN, source_id="data_labeler_001"
),
metadata={"labeling_session": "batch_01", "confidence": 0.95},
)
log_feedback(*, trace_id: str, name: str = 'feedback', value: float | int | str | bool | dict[str, float | int | str | bool] | list[float | int | str | bool] | None = None, source: mlflow.entities.assessment_source.AssessmentSource | None = None, error: Exception | mlflow.entities.assessment_error.AssessmentError | None = None, rationale: str | None = None, metadata: dict[str, typing.Any] | None = None, span_id: str | None = None) -> mlflow.entities.assessment.Assessment
Logs feedback to a Trace. This API only takes keyword arguments.
Args:
trace_id: The ID of the trace.
name: The name of the feedback assessment e.g., "faithfulness". Defaults to
"feedback" if not provided.
value: The value of the feedback. Can be ``None``, or one of the following types:
- float
- int
- str
- bool
- list of values of the same types as above
- dict with string keys and values of the same types as above
source: The source of the feedback assessment. Must be an instance of
:py:class:`~mlflow.entities.AssessmentSource`. If not provided, defaults to
CODE source type
error: An error object representing any issues encountered while computing the
feedback, e.g., a timeout error from an LLM judge. Accepts an exception
object, or an :py:class:`~mlflow.entities.AssessmentError` object. Either
this or `value` must be provided.
rationale: The rationale / justification for the feedback.
metadata: Additional metadata for the feedback.
span_id: The ID of the span associated with the feedback, if it needs be
associated with a specific span in the trace.
Returns:
:py:class:`~mlflow.entities.Assessment`: The created feedback assessment.
Examples:
.. code-block:: python
import mlflow
from mlflow.entities import AssessmentSource, AssessmentSourceType
# Log simple feedback score
feedback = mlflow.log_feedback(
trace_id="tr-1234567890abcdef",
name="relevance",
value=0.9,
source=AssessmentSource(
source_type=AssessmentSourceType.LLM_JUDGE, source_id="gpt-4"
),
rationale="Response directly addresses the user's question",
)
# Log detailed feedback with structured data
mlflow.log_feedback(
trace_id="tr-1234567890abcdef",
name="quality_metrics",
value={"accuracy": 0.95, "completeness": 0.88, "clarity": 0.92, "overall": 0.92},
source=AssessmentSource(
source_type=AssessmentSourceType.HUMAN, source_id="expert_evaluator"
),
rationale="High accuracy and clarity, slightly incomplete coverage",
)
log_figure(figure: Union[ForwardRef('matplotlib.figure.Figure'), ForwardRef('plotly.graph_objects.Figure')], artifact_file: str, *, save_kwargs: dict[str, typing.Any] | None = None) -> None
Log a figure as an artifact. The following figure objects are supported:
- `matplotlib.figure.Figure`_
- `plotly.graph_objects.Figure`_
.. _matplotlib.figure.Figure:
https://matplotlib.org/api/_as_gen/matplotlib.figure.Figure.html
.. _plotly.graph_objects.Figure:
https://plotly.com/python-api-reference/generated/plotly.graph_objects.Figure.html
Args:
figure: Figure to log.
artifact_file: The run-relative artifact file path in posixpath format to which
the figure is saved (e.g. "dir/file.png").
save_kwargs: Additional keyword arguments passed to the method that saves the figure.
.. code-block:: python
:test:
:caption: Matplotlib Example
import mlflow
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([0, 1], [2, 3])
with mlflow.start_run():
mlflow.log_figure(fig, "figure.png")
.. code-block:: python
:test:
:caption: Plotly Example
import mlflow
from plotly import graph_objects as go
fig = go.Figure(go.Scatter(x=[0, 1], y=[2, 3]))
with mlflow.start_run():
mlflow.log_figure(fig, "figure.html")
log_image(image: Union[ForwardRef('numpy.ndarray'), ForwardRef('PIL.Image.Image'), ForwardRef('mlflow.Image')], artifact_file: str | None = None, key: str | None = None, step: int | None = None, timestamp: int | None = None, synchronous: bool | None = False) -> None
Logs an image in MLflow, supporting two use cases:
1. Time-stepped image logging:
Ideal for tracking changes or progressions through iterative processes (e.g.,
during model training phases).
- Usage: :code:`log_image(image, key=key, step=step, timestamp=timestamp)`
2. Artifact file image logging:
Best suited for static image logging where the image is saved directly as a file
artifact.
- Usage: :code:`log_image(image, artifact_file)`
The following image formats are supported:
- `numpy.ndarray`_
- `PIL.Image.Image`_
.. _numpy.ndarray:
https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html
.. _PIL.Image.Image:
https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image
- :class:`mlflow.Image`: An MLflow wrapper around PIL image for convenient image logging.
Numpy array support
- data types:
- bool (useful for logging image masks)
- integer [0, 255]
- unsigned integer [0, 255]
- float [0.0, 1.0]
.. warning::
- Out-of-range integer values will raise ValueError.
- Out-of-range float values will auto-scale with min/max and warn.
- shape (H: height, W: width):
- H x W (Grayscale)
- H x W x 1 (Grayscale)
- H x W x 3 (an RGB channel order is assumed)
- H x W x 4 (an RGBA channel order is assumed)
Args:
image: The image object to be logged.
artifact_file: Specifies the path, in POSIX format, where the image
will be stored as an artifact relative to the run's root directory (for
example, "dir/image.png"). This parameter is kept for backward compatibility
and should not be used together with `key`, `step`, or `timestamp`.
key: Image name for time-stepped image logging. This string may only contain
alphanumerics, underscores (_), dashes (-), periods (.), spaces ( ), and
slashes (/).
step: Integer training step (iteration) at which the image was saved.
Defaults to 0.
timestamp: Time when this image was saved. Defaults to the current system time.
synchronous: *Experimental* If True, blocks until the image is logged successfully.
.. code-block:: python
:caption: Time-stepped image logging numpy example
import mlflow
import numpy as np
image = np.random.randint(0, 256, size=(100, 100, 3), dtype=np.uint8)
with mlflow.start_run():
mlflow.log_image(image, key="dogs", step=3)
.. code-block:: python
:caption: Time-stepped image logging pillow example
import mlflow
from PIL import Image
image = Image.new("RGB", (100, 100))
with mlflow.start_run():
mlflow.log_image(image, key="dogs", step=3)
.. code-block:: python
:caption: Time-stepped image logging with mlflow.Image example
import mlflow
from PIL import Image
# If you have a preexisting saved image
Image.new("RGB", (100, 100)).save("image.png")
image = mlflow.Image("image.png")
with mlflow.start_run() as run:
mlflow.log_image(run.info.run_id, image, key="dogs", step=3)
.. code-block:: python
:caption: Legacy artifact file image logging numpy example
import mlflow
import numpy as np
image = np.random.randint(0, 256, size=(100, 100, 3), dtype=np.uint8)
with mlflow.start_run():
mlflow.log_image(image, "image.png")
.. code-block:: python
:caption: Legacy artifact file image logging pillow example
import mlflow
from PIL import Image
image = Image.new("RGB", (100, 100))
with mlflow.start_run():
mlflow.log_image(image, "image.png")
log_input(dataset: Optional[ForwardRef('Dataset')] = None, context: str | None = None, tags: dict[str, str] | None = None, model: mlflow.entities.logged_model_input.LoggedModelInput | None = None) -> None
Log a dataset used in the current run.
Args:
dataset: :py:class:`mlflow.data.dataset.Dataset` object to be logged.
context: Context in which the dataset is used. For example: "training", "testing".
This will be set as an input tag with key `mlflow.data.context`.
tags: Tags to be associated with the dataset. Dictionary of tag_key -> tag_value.
model: A :py:class:`mlflow.entities.LoggedModelInput` instance to log as input to
the run.
.. code-block:: python
:test:
:caption: Example
import numpy as np
import mlflow
array = np.asarray([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
dataset = mlflow.data.from_numpy(array, source="data.csv")
# Log an input dataset used for training
with mlflow.start_run():
mlflow.log_input(dataset, context="training")
log_inputs(datasets: list[typing.Optional[ForwardRef('Dataset')]] | None = None, contexts: list[str | None] | None = None, tags_list: list[dict[str, str] | None] | None = None, models: list[mlflow.entities.logged_model_input.LoggedModelInput | None] | None = None) -> None
Log a batch of datasets used in the current run.
The lists of `datasets`, `contexts`, `tags_list` must have the same length.
The entries in these lists can be ``None``, which represents empty value to the
corresponding input.
Args:
datasets: List of :py:class:`mlflow.data.dataset.Dataset` object to be logged.
contexts: List of context in which the dataset is used. For example: "training", "testing".
This will be set as an input tag with key `mlflow.data.context`.
tags_list: List of tags to be associated with the dataset. Dictionary of
tag_key -> tag_value.
models: List of :py:class:`mlflow.entities.LoggedModelInput` instance to log as input
to the run. Currently only Databricks managed MLflow supports this argument.
.. code-block:: python
:test:
:caption: Example
import numpy as np
import mlflow
array = np.asarray([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
dataset = mlflow.data.from_numpy(array, source="data.csv")
array2 = np.asarray([[-1, 2, 3], [-4, 5, 6]])
dataset2 = mlflow.data.from_numpy(array2, source="data2.csv")
# Log 2 input datasets used for training and test,
# the training dataset has no tag.
# the test dataset has tags `{"my_tag": "tag_value"}`.
with mlflow.start_run():
mlflow.log_inputs(
[dataset, dataset2],
contexts=["training", "test"],
tags_list=[None, {"my_tag": "tag_value"}],
models=None,
)
log_issue(*, trace_id: str, issue_id: str, issue_name: str | None = None, source: mlflow.entities.assessment_source.AssessmentSource | None = None, run_id: str | None = None, rationale: str | None = None, metadata: dict[str, str] | None = None, span_id: str | None = None) -> mlflow.entities.assessment.Assessment
Logs an issue reference to a Trace. This links a trace to a discovered issue.
This API only takes keyword arguments.
Args:
trace_id: The ID of the trace.
issue_id: The ID of the issue to reference.
issue_name: The name of the issue. If not provided, the issue name will be fetched
using the issue ID.
source: The source represents how this issue was detected on the trace, for example,
human review or automatic AI scan. Must be an instance of
:py:class:`~mlflow.entities.AssessmentSource`. If not provided, defaults to
LLM_JUDGE source type.
run_id: The ID of the run that detect the issue on the given trace.
rationale: The rationale / justification for the issue reference.
metadata: Additional metadata for the issue reference.
span_id: The ID of the span associated with the issue, if it needs to be
associated with a specific span in the trace.
Returns:
:py:class:`~mlflow.entities.Assessment`: The created issue reference assessment.
Examples:
.. code-block:: python
import mlflow
from mlflow.entities import AssessmentSource, AssessmentSourceType
# Log an issue reference to link a trace to a discovered issue
issue_ref = mlflow.log_issue(
trace_id="tr-1234567890abcdef",
issue_id="iss-abcdef123456",
source=AssessmentSource(
source_type=AssessmentSourceType.LLM_JUDGE, source_id="issue-discovery-agent"
),
run_id="run-123",
rationale="Response time exceeded 2 seconds threshold",
)
log_metric(key: str, value: float, step: int | None = None, synchronous: bool | None = None, timestamp: int | None = None, run_id: str | None = None, model_id: str | None = None, dataset: Union[ForwardRef('Dataset'), mlflow.entities.dataset.Dataset, NoneType] = None) -> mlflow.utils.async_logging.run_operations.RunOperations | None
Log a metric under the current run. If no run is active, this method will create
a new active run.
Args:
key: Metric name. This string may only contain alphanumerics, underscores (_),
dashes (-), periods (.), spaces ( ), and slashes (/).
All backend stores will support keys up to length 250, but some may
support larger keys.
value: Metric value. Note that some special values such as +/- Infinity may be
replaced by other values depending on the store. For example, the
SQLAlchemy store replaces +/- Infinity with max / min float values.
All backend stores will support values up to length 5000, but some
may support larger values.
step: Metric step. Defaults to zero if unspecified.
synchronous: *Experimental* If True, blocks until the metric is logged
successfully. If False, logs the metric asynchronously and
returns a future representing the logging operation. If None, read from environment
variable `MLFLOW_ENABLE_ASYNC_LOGGING`, which defaults to False if not set.
timestamp: Time when this metric was calculated. Defaults to the current system time.
run_id: If specified, log the metric to the specified run. If not specified, log the metric
to the currently active run.
model_id: The ID of the model associated with the metric. If not specified, use the current
active model ID set by :py:func:`mlflow.set_active_model`. If no active model exists,
the models IDs associated with the specified or active run will be used.
dataset: The dataset associated with the metric.
Returns:
When `synchronous=True`, returns None.
When `synchronous=False`, returns `RunOperations` that represents future for
logging operation.
.. code-block:: python
:test:
:caption: Example
import mlflow
# Log a metric
with mlflow.start_run():
mlflow.log_metric("mse", 2500.00)
# Log a metric in async fashion.
with mlflow.start_run():
mlflow.log_metric("mse", 2500.00, synchronous=False)
log_metrics(metrics: dict[str, float], step: int | None = None, synchronous: bool | None = None, run_id: str | None = None, timestamp: int | None = None, model_id: str | None = None, dataset: Union[ForwardRef('Dataset'), mlflow.entities.dataset.Dataset, NoneType] = None) -> mlflow.utils.async_logging.run_operations.RunOperations | None
Log multiple metrics for the current run. If no run is active, this method will create a new
active run.
Args:
metrics: Dictionary of metric_name: String -> value: Float. Note that some special
values such as +/- Infinity may be replaced by other values depending on
the store. For example, sql based store may replace +/- Infinity with
max / min float values.
step: A single integer step at which to log the specified
Metrics. If unspecified, each metric is logged at step zero.
synchronous: *Experimental* If True, blocks until the metrics are logged
successfully. If False, logs the metrics asynchronously and
returns a future representing the logging operation. If None, read from environment
variable `MLFLOW_ENABLE_ASYNC_LOGGING`, which defaults to False if not set.
run_id: Run ID. If specified, log metrics to the specified run. If not specified, log
metrics to the currently active run.
timestamp: Time when these metrics were calculated. Defaults to the current system time.
model_id: The ID of the model associated with the metric. If not specified, use the current
active model ID set by :py:func:`mlflow.set_active_model`. If no active model
exists, the models IDs associated with the specified or active run will be used.
dataset: The dataset associated with the metrics.
Returns:
When `synchronous=True`, returns None. When `synchronous=False`, returns an
:py:class:`mlflow.utils.async_logging.run_operations.RunOperations` instance that
represents future for logging operation.
.. code-block:: python
:test:
:caption: Example
import mlflow
metrics = {"mse": 2500.00, "rmse": 50.00}
# Log a batch of metrics
with mlflow.start_run():
mlflow.log_metrics(metrics)
# Log a batch of metrics in async fashion.
with mlflow.start_run():
mlflow.log_metrics(metrics, synchronous=False)
log_model_params(params: dict[str, str], model_id: str | None = None) -> None
Log params to the specified logged model.
Args:
params: Params to log on the model.
model_id: ID of the model. If not specified, use the current active model ID.
Returns:
None
Example:
.. code-block:: python
:test:
import mlflow
class DummyModel(mlflow.pyfunc.PythonModel):
def predict(self, context, model_input: list[str]) -> list[str]:
return model_input
model_info = mlflow.pyfunc.log_model(name="model", python_model=DummyModel())
mlflow.log_model_params(params={"param": "value"}, model_id=model_info.model_id)
log_outputs(models: list[mlflow.entities.logged_model_output.LoggedModelOutput] | None = None)
Log outputs, such as models, to the active run. If there is no active run, a new run will be
created.
Args:
models: List of :py:class:`mlflow.entities.LoggedModelOutput` instances to log
as outputs to the run.
Returns:
None.
log_param(key: str, value: Any, synchronous: bool | None = None) -> Any
Log a parameter (e.g. model hyperparameter) under the current run. If no run is active,
this method will create a new active run.
Args:
key: Parameter name. This string may only contain alphanumerics, underscores (_), dashes
(-), periods (.), spaces ( ), and slashes (/). All backend stores support keys up to
length 250, but some may support larger keys.
value: Parameter value, but will be string-ified if not. All built-in backend stores support
values up to length 6000, but some may support larger values.
synchronous: *Experimental* If True, blocks until the parameter is logged successfully. If
False, logs the parameter asynchronously and returns a future representing the logging
operation. If None, read from environment variable `MLFLOW_ENABLE_ASYNC_LOGGING`,
which defaults to False if not set.
Returns:
When `synchronous=True`, returns parameter value. When `synchronous=False`, returns an
:py:class:`mlflow.utils.async_logging.run_operations.RunOperations` instance that represents
future for logging operation.
.. code-block:: python
:test:
:caption: Example
import mlflow
with mlflow.start_run():
value = mlflow.log_param("learning_rate", 0.01)
assert value == 0.01
value = mlflow.log_param("learning_rate", 0.02, synchronous=False)
log_params(params: dict[str, typing.Any], synchronous: bool | None = None, run_id: str | None = None) -> mlflow.utils.async_logging.run_operations.RunOperations | None
Log a batch of params for the current run. If no run is active, this method will create a
new active run.
Args:
params: Dictionary of param_name: String -> value: (String, but will be string-ified if
not)
synchronous: *Experimental* If True, blocks until the parameters are logged
successfully. If False, logs the parameters asynchronously and
returns a future representing the logging operation. If None, read from environment
variable `MLFLOW_ENABLE_ASYNC_LOGGING`, which defaults to False if not set.
run_id: Run ID. If specified, log params to the specified run. If not specified, log
params to the currently active run.
Returns:
When `synchronous=True`, returns None. When `synchronous=False`, returns an
:py:class:`mlflow.utils.async_logging.run_operations.RunOperations` instance that
represents future for logging operation.
.. code-block:: python
:test:
:caption: Example
import mlflow
params = {"learning_rate": 0.01, "n_estimators": 10}
# Log a batch of parameters
with mlflow.start_run():
mlflow.log_params(params)
# Log a batch of parameters in async fashion.
with mlflow.start_run():
mlflow.log_params(params, synchronous=False)
log_stream(stream: io.BufferedIOBase | io.RawIOBase, artifact_file: str, run_id: str | None = None) -> None
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Log a binary file-like object (e.g., ``io.BytesIO``) as an artifact.
Args:
stream: A binary file-like object supporting ``.read()`` method (e.g., ``io.BytesIO``).
artifact_file: The run-relative artifact file path in posixpath format to which
the stream content is saved (e.g. "dir/file.bin").
run_id: If specified, log the artifact to the specified run. If not specified, log the
artifact to the currently active run.
.. code-block:: python
:test:
:caption: Example
import io
import mlflow
with mlflow.start_run():
# Log a BytesIO stream
bytes_stream = io.BytesIO(b"binary content")
mlflow.log_stream(bytes_stream, "binary_file.bin")
log_table(data: Union[dict[str, Any], ForwardRef('pandas.DataFrame')], artifact_file: str, run_id: str | None = None) -> None
Log a table to MLflow Tracking as a JSON artifact. If the artifact_file already exists
in the run, the data would be appended to the existing artifact_file.
Args:
data: Dictionary or pandas.DataFrame to log.
artifact_file: The run-relative artifact file path in posixpath format to which
the table is saved (e.g. "dir/file.json").
run_id: If specified, log the table to the specified run. If not specified, log the
table to the currently active run.
.. code-block:: python
:test:
:caption: Dictionary Example
import mlflow
table_dict = {
"inputs": ["What is MLflow?", "What is Databricks?"],
"outputs": ["MLflow is ...", "Databricks is ..."],
"toxicity": [0.0, 0.0],
}
with mlflow.start_run():
# Log the dictionary as a table
mlflow.log_table(data=table_dict, artifact_file="qabot_eval_results.json")
.. code-block:: python
:test:
:caption: Pandas DF Example
import mlflow
import pandas as pd
table_dict = {
"inputs": ["What is MLflow?", "What is Databricks?"],
"outputs": ["MLflow is ...", "Databricks is ..."],
"toxicity": [0.0, 0.0],
}
df = pd.DataFrame.from_dict(table_dict)
with mlflow.start_run():
# Log the df as a table
mlflow.log_table(data=df, artifact_file="qabot_eval_results.json")
log_text(text: str, artifact_file: str, run_id: str | None = None) -> None
Log text as an artifact.
Args:
text: String containing text to log.
artifact_file: The run-relative artifact file path in posixpath format to which
the text is saved (e.g. "dir/file.txt").
run_id: If specified, log the artifact to the specified run. If not specified, log the
artifact to the currently active run.
.. code-block:: python
:test:
:caption: Example
import mlflow
with mlflow.start_run():
# Log text to a file under the run's root artifact directory
mlflow.log_text("text1", "file1.txt")
# Log text in a subdirectory of the run's root artifact directory
mlflow.log_text("text2", "dir/file2.txt")
# Log HTML text
mlflow.log_text("<h1>header</h1>", "index.html")
log_trace(name: 'str' = 'Task', request: 'Any | None' = None, response: 'Any | None' = None, intermediate_outputs: 'dict[str, Any] | None' = None, attributes: 'dict[str, Any] | None' = None, tags: 'dict[str, str] | None' = None, start_time_ms: 'int | None' = None, execution_time_ms: 'int | None' = None) -> 'str'
.. Warning:: ``mlflow.tracing.fluent.log_trace`` is deprecated since 3.6.0. This method will be removed in a future release.
Create a trace with a single root span.
This API is useful when you want to log an arbitrary (request, response) pair
without structured OpenTelemetry spans. The trace is linked to the active experiment.
Args:
name: The name of the trace (and the root span). Default to "Task".
request: Input data for the entire trace. This is also set on the root span of the trace.
response: Output data for the entire trace. This is also set on the root span of the trace.
intermediate_outputs: A dictionary of intermediate outputs produced by the model or agent
while handling the request. Keys are the names of the outputs,
and values are the outputs themselves. Values must be JSON-serializable.
attributes: A dictionary of attributes to set on the root span of the trace.
tags: A dictionary of tags to set on the trace.
start_time_ms: The start time of the trace in milliseconds since the UNIX epoch.
When not specified, current time is used for start and end time of the trace.
execution_time_ms: The execution time of the trace in milliseconds since the UNIX epoch.
Returns:
The ID of the logged trace.
Example:
.. code-block:: python
:test:
import time
import mlflow
trace_id = mlflow.log_trace(
request="Does mlflow support tracing?",
response="Yes",
intermediate_outputs={
"retrieved_documents": ["mlflow documentation"],
"system_prompt": ["answer the question with yes or no"],
},
start_time_ms=int(time.time() * 1000),
execution_time_ms=5129,
)
trace = mlflow.get_trace(trace_id, flush=True)
print(trace.data.intermediate_outputs)
login(backend: str = 'databricks', interactive: bool = True) -> None
Configure MLflow server authentication and connect MLflow to tracking server.
This method provides a simple way to connect MLflow to its tracking server. Currently only
Databricks tracking server is supported. Users will be prompted to enter the credentials if no
existing Databricks profile is found, and the credentials will be saved to `~/.databrickscfg`.
Args:
backend: string, the backend of the tracking server. Currently only "databricks" is
supported.
interactive: bool, controls request for user input on missing credentials. If true, user
input will be requested if no credentials are found, otherwise an exception will be
raised if no credentials are found.
.. code-block:: python
:caption: Example
import mlflow
mlflow.login()
with mlflow.start_run():
mlflow.log_param("p", 0)
override_feedback(*, trace_id: str, assessment_id: str, value: float | int | str | bool | dict[str, float | int | str | bool] | list[float | int | str | bool], rationale: str | None = None, source: mlflow.entities.assessment_source.AssessmentSource | None = None, metadata: dict[str, typing.Any] | None = None) -> mlflow.entities.assessment.Assessment
Overrides an existing feedback assessment with a new assessment. This API
logs a new assessment with the `overrides` field set to the provided assessment ID.
The original assessment will be marked as invalid, but will otherwise be unchanged.
This is useful when you want to correct an assessment generated by an LLM judge,
but want to preserve the original assessment for future judge fine-tuning.
If you want to mutate an assessment in-place, use :py:func:`update_assessment` instead.
Args:
trace_id: The ID of the trace.
assessment_id: The ID of the assessment to override.
value: The new value of the assessment.
rationale: The rationale of the new assessment.
source: The source of the new assessment.
metadata: Additional metadata for the new assessment.
Returns:
:py:class:`~mlflow.entities.Assessment`: The created assessment.
Examples:
.. code-block:: python
import mlflow
from mlflow.entities import AssessmentSource, AssessmentSourceType
# First, log an initial LLM-generated feedback as a simulation
llm_feedback = mlflow.log_feedback(
trace_id="tr-1234567890abcdef",
name="relevance",
value=0.6,
source=AssessmentSource(
source_type=AssessmentSourceType.LLM_JUDGE, source_id="gpt-4"
),
rationale="Response partially addresses the question",
)
# Later, a human reviewer disagrees and wants to override
corrected_assessment = mlflow.override_feedback(
trace_id="tr-1234567890abcdef",
assessment_id=llm_feedback.assessment_id,
value=0.9,
rationale="Response fully addresses the question with good examples",
source=AssessmentSource(
source_type=AssessmentSourceType.HUMAN, source_id="expert_reviewer@company.com"
),
metadata={
"override_reason": "LLM underestimated relevance",
"review_date": "2024-01-15",
"confidence": "high",
},
)
register_model(model_uri, name, await_registration_for=300, *, tags: dict[str, typing.Any] | None = None, env_pack: Union[Literal['databricks_model_serving'], mlflow.utils.env_pack.EnvPackConfig, NoneType] = None) -> mlflow.entities.model_registry.model_version.ModelVersion
Create a new model version in model registry for the model files specified by ``model_uri``.
Note that this method assumes the model registry backend URI is the same as that of the
tracking backend.
Args:
model_uri: URI referring to the MLmodel directory. Supported URI schemes include:
- ``runs:/`` URIs (e.g., ``runs:/<run_id>/<artifact_path>``) to register a model
from a specific run. The run ID is recorded with the model version.
- ``models:/`` URIs, which support two forms:
- ``models:/<model_name>/<version>`` to promote an existing registered
model version. The source run lineage is preserved when the
referenced model version has an associated source run.
- ``models:/<model_id>`` to create a new registered model version from a logged
model (for example, one returned by ``log_model``). The source
run lineage is preserved.
- Local filesystem paths for registering locally-persisted MLflow models that were
previously saved using ``save_model``.
name: Name of the registered model under which to create a new model version. If a
registered model with the given name does not exist, it will be created
automatically.
await_registration_for: Number of seconds to wait for the model version to finish
being created and is in ``READY`` status. By default, the function
waits for five minutes. Specify 0 or None to skip waiting.
tags: A dictionary of key-value pairs that are converted into
:py:class:`mlflow.entities.model_registry.ModelVersionTag` objects.
env_pack: Either a string or an EnvPackConfig. If specified,
the model dependencies are optionally first installed into the current Python
environment, and then the complete environment will be packaged and included
in the registered model artifacts. If the string shortcut "databricks_model_serving" is
used, then model dependencies will be installed in the current environment. This is
useful when deploying the model to a serving environment like Databricks Model Serving.
.. Note:: Experimental: This parameter may change or be removed in a future
release without warning.
Returns:
Single :py:class:`mlflow.entities.model_registry.ModelVersion` object created by
backend.
.. code-block:: python
:test:
:caption: Example
import mlflow.sklearn
from mlflow.models import infer_signature
from sklearn.datasets import make_regression
from sklearn.ensemble import RandomForestRegressor
mlflow.set_tracking_uri("sqlite:////tmp/mlruns.db")
params = {"n_estimators": 3, "random_state": 42}
X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
# Log MLflow entities
with mlflow.start_run() as run:
rfr = RandomForestRegressor(**params).fit(X, y)
signature = infer_signature(X, rfr.predict(X))
mlflow.log_params(params)
mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
model_uri = f"runs:/{run.info.run_id}/sklearn-model"
mv = mlflow.register_model(model_uri, "RandomForestRegressionModel")
print(f"Name: {mv.name}")
print(f"Version: {mv.version}")
.. code-block:: text
:caption: Output
Name: RandomForestRegressionModel
Version: 1
register_prompt(name: str, template: str | list[dict[str, typing.Any]], commit_message: str | None = None, tags: dict[str, str] | None = None, response_format: type[pydantic.main.BaseModel] | dict[str, typing.Any] | None = None, model_config: 'PromptModelConfig | dict[str, Any] | None' = None) -> mlflow.entities.model_registry.prompt_version.PromptVersion
Register a new :py:class:`Prompt <mlflow.entities.Prompt>` in the MLflow Prompt Registry.
A :py:class:`Prompt <mlflow.entities.Prompt>` is a pair of name and
template content at minimum. With MLflow Prompt Registry, you can create, manage, and
version control prompts with the MLflow's robust model tracking framework.
If there is no registered prompt with the given name, a new prompt will be created.
Otherwise, a new version of the existing prompt will be created.
Args:
name: The name of the prompt.
template: The template content of the prompt. Can be either:
- A string containing text with variables enclosed in double curly braces,
e.g. {{variable}}, which will be replaced with actual values by the `format` method.
- A list of dictionaries representing chat messages, where each message has
'role' and 'content' keys (e.g., [{"role": "user", "content": "Hello {{name}}"}])
.. note::
If you want to use the prompt with a framework that uses single curly braces
e.g. LangChain, you can use the `to_single_brace_format` method to convert the
loaded prompt to a format that uses single curly braces.
.. code-block:: python
prompt = client.load_prompt("my_prompt")
langchain_format = prompt.to_single_brace_format()
commit_message: A message describing the changes made to the prompt, similar to a
Git commit message. Optional.
tags: A dictionary of tags associated with the **prompt version**.
This is useful for storing version-specific information, such as the author of
the changes. Optional.
response_format: Optional Pydantic class or dictionary defining the expected response
structure. This can be used to specify the schema for structured outputs from LLM calls.
model_config: Optional PromptModelConfig instance or dictionary containing model-specific
configuration. Using PromptModelConfig provides validation and type safety.
Returns:
A :py:class:`Prompt <mlflow.entities.Prompt>` object that was created.
Example:
.. code-block:: python
import mlflow
from pydantic import BaseModel
# Register a text prompt
mlflow.register_prompt(
name="greeting_prompt",
template="Respond to the user's message as a {{style}} AI.",
response_format={"type": "string", "description": "A friendly response"},
)
# Register a chat prompt with multiple messages
mlflow.register_prompt(
name="assistant_prompt",
template=[
{"role": "system", "content": "You are a helpful {{style}} assistant."},
{"role": "user", "content": "{{question}}"},
],
response_format={"type": "object", "properties": {"answer": {"type": "string"}}},
)
# Load the prompt from the registry
prompt = mlflow.load_prompt("greeting_prompt")
# Use the prompt in your application
import openai
openai_client = openai.OpenAI()
openai_client.chat.completion.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": prompt.format(style="friendly")},
{"role": "user", "content": "Hello, how are you?"},
],
)
# Update the prompt with a new version
prompt = mlflow.register_prompt(
name="greeting_prompt",
template="Respond to the user's message as a {{style}} AI. {{greeting}}",
commit_message="Add a greeting to the prompt.",
tags={"author": "Bob"},
)
run(uri, entry_point='main', version=None, parameters=None, docker_args=None, experiment_name=None, experiment_id=None, backend='local', backend_config=None, storage_dir=None, synchronous=True, run_id=None, run_name=None, env_manager=None, build_image=False, docker_auth=None)
Run an MLflow project. The project can be local or stored at a Git URI.
MLflow provides built-in support for running projects locally or remotely on a Databricks or
Kubernetes cluster. You can also run projects against other targets by installing an appropriate
third-party plugin. See `Community Plugins <../plugins.html#community-plugins>`_ for more
information.
For information on using this method in chained workflows, see `Building Multistep Workflows
<../projects.html#building-multistep-workflows>`_.
Raises:
:py:class:`mlflow.exceptions.ExecutionException` If a run launched in blocking mode
is unsuccessful.
Args:
uri: URI of project to run. A local filesystem path
or a Git repository URI (e.g. https://github.com/mlflow/mlflow-example)
pointing to a project directory containing an MLproject file.
entry_point: Entry point to run within the project. If no entry point with the specified
name is found, runs the project file ``entry_point`` as a script,
using "python" to run ``.py`` files and the default shell (specified by
environment variable ``$SHELL``) to run ``.sh`` files.
version: For Git-based projects, either a commit hash or a branch name.
parameters: Parameters (dictionary) for the entry point command.
docker_args: Arguments (dictionary) for the docker command.
experiment_name: Name of experiment under which to launch the run.
experiment_id: ID of experiment under which to launch the run.
backend: Execution backend for the run: MLflow provides built-in support for "local",
"databricks", and "kubernetes" (experimental) backends. If running against
Databricks, will run against a Databricks workspace determined as follows:
if a Databricks tracking URI of the form ``databricks://profile`` has been set
(e.g. by setting the MLFLOW_TRACKING_URI environment variable), will run
against the workspace specified by <profile>. Otherwise, runs against the
workspace specified by the default Databricks CLI profile.
backend_config: A dictionary, or a path to a JSON file (must end in '.json'), which will
be passed as config to the backend. The exact content which should be
provided is different for each execution backend and is documented
at https://www.mlflow.org/docs/latest/projects.html.
storage_dir: Used only if ``backend`` is "local". MLflow downloads artifacts from
distributed URIs passed to parameters of type ``path`` to subdirectories of
``storage_dir``.
synchronous: Whether to block while waiting for a run to complete. Defaults to True.
Note that if ``synchronous`` is False and ``backend`` is "local", this
method will return, but the current process will block when exiting until
the local run completes. If the current process is interrupted, any
asynchronous runs launched via this method will be terminated. If
``synchronous`` is True and the run fails, the current process will
error out as well.
run_id: Note: this argument is used internally by the MLflow project APIs and should
not be specified. If specified, the run ID will be used instead of
creating a new run.
run_name: The name to give the MLflow Run associated with the project execution.
If ``None``, the MLflow Run name is left unset.
env_manager: Specify an environment manager to create a new environment for the run and
install project dependencies within that environment. The following values
are supported:
- local: use the local environment
- virtualenv: use virtualenv (and pyenv for Python version management)
- uv: use uv
- conda: use conda
If unspecified, MLflow automatically determines the environment manager to
use by inspecting files in the project directory. For example, if
``python_env.yaml`` is present, virtualenv will be used.
build_image: Whether to build a new docker image of the project or to reuse an existing
image. Default: False (reuse an existing image)
docker_auth: A dictionary representing information to authenticate with a Docker
registry. See `docker.client.DockerClient.login
<https://docker-py.readthedocs.io/en/stable/client.html#docker.client.DockerClient.login>`_
for available options.
Returns:
:py:class:`mlflow.projects.SubmittedRun` exposing information (e.g. run ID)
about the launched run.
.. code-block:: python
:caption: Example
import mlflow
project_uri = "https://github.com/mlflow/mlflow-example"
params = {"alpha": 0.5, "l1_ratio": 0.01}
# Run MLflow project and create a reproducible conda environment
# on a local host
mlflow.run(project_uri, parameters=params)
.. code-block:: text
:caption: Output
...
...
Elasticnet model (alpha=0.500000, l1_ratio=0.010000):
RMSE: 0.788347345611717
MAE: 0.6155576449938276
R2: 0.19729662005412607
... mlflow.projects: === Run (ID '6a5109febe5e4a549461e149590d0a7c') succeeded ===
search_experiments(view_type: int = 1, max_results: int | None = None, filter_string: str | None = None, order_by: list[str] | None = None) -> list[mlflow.entities.experiment.Experiment]
Search for experiments that match the specified search query.
Args:
view_type: One of enum values ``ACTIVE_ONLY``, ``DELETED_ONLY``, or ``ALL``
defined in :py:class:`mlflow.entities.ViewType`.
max_results: If passed, specifies the maximum number of experiments desired. If not
passed, all experiments will be returned.
filter_string: Filter query string (e.g., ``"name = 'my_experiment'"``), defaults to
searching for all experiments. The following identifiers, comparators, and logical
operators are supported.
Identifiers
- ``name``: Experiment name
- ``creation_time``: Experiment creation time
- ``last_update_time``: Experiment last update time
- ``tags.<tag_key>``: Experiment tag. If ``tag_key`` contains
spaces, it must be wrapped with backticks (e.g., ``"tags.`extra key`"``).
Comparators for string attributes and tags
- ``=``: Equal to
- ``!=``: Not equal to
- ``LIKE``: Case-sensitive pattern match
- ``ILIKE``: Case-insensitive pattern match
Comparators for numeric attributes
- ``=``: Equal to
- ``!=``: Not equal to
- ``<``: Less than
- ``<=``: Less than or equal to
- ``>``: Greater than
- ``>=``: Greater than or equal to
Logical operators
- ``AND``: Combines two sub-queries and returns True if both of them are True.
order_by: List of columns to order by. The ``order_by`` column can contain an optional
``DESC`` or ``ASC`` value (e.g., ``"name DESC"``). The default ordering is ``ASC``,
so ``"name"`` is equivalent to ``"name ASC"``. If unspecified, defaults to
``["last_update_time DESC"]``, which lists experiments updated most recently first.
The following fields are supported:
- ``experiment_id``: Experiment ID
- ``name``: Experiment name
- ``creation_time``: Experiment creation time
- ``last_update_time``: Experiment last update time
Returns:
A list of :py:class:`Experiment <mlflow.entities.Experiment>` objects.
.. code-block:: python
:test:
:caption: Example
import mlflow
def assert_experiment_names_equal(experiments, expected_names):
actual_names = [e.name for e in experiments if e.name != "Default"]
assert actual_names == expected_names, (actual_names, expected_names)
mlflow.set_tracking_uri("sqlite:///:memory:")
# Create experiments
for name, tags in [
("a", None),
("b", None),
("ab", {"k": "v"}),
("bb", {"k": "V"}),
]:
mlflow.create_experiment(name, tags=tags)
# Search for experiments with name "a"
experiments = mlflow.search_experiments(filter_string="name = 'a'")
assert_experiment_names_equal(experiments, ["a"])
# Search for experiments with name starting with "a"
experiments = mlflow.search_experiments(filter_string="name LIKE 'a%'")
assert_experiment_names_equal(experiments, ["ab", "a"])
# Search for experiments with tag key "k" and value ending with "v" or "V"
experiments = mlflow.search_experiments(filter_string="tags.k ILIKE '%v'")
assert_experiment_names_equal(experiments, ["bb", "ab"])
# Search for experiments with name ending with "b" and tag {"k": "v"}
experiments = mlflow.search_experiments(filter_string="name LIKE '%b' AND tags.k = 'v'")
assert_experiment_names_equal(experiments, ["ab"])
# Sort experiments by name in ascending order
experiments = mlflow.search_experiments(order_by=["name"])
assert_experiment_names_equal(experiments, ["a", "ab", "b", "bb"])
# Sort experiments by ID in descending order
experiments = mlflow.search_experiments(order_by=["experiment_id DESC"])
assert_experiment_names_equal(experiments, ["bb", "ab", "b", "a"])
search_logged_models(experiment_ids: list[str] | None = None, filter_string: str | None = None, datasets: list[dict[str, str]] | None = None, max_results: int | None = None, order_by: list[dict[str, typing.Any]] | None = None, output_format: Literal['pandas', 'list'] = 'pandas') -> Union[list[mlflow.entities.logged_model.LoggedModel], ForwardRef('pandas.DataFrame')]
Search for logged models that match the specified search criteria.
Args:
experiment_ids: List of experiment IDs to search for logged models. If not specified,
the active experiment will be used.
filter_string: A SQL-like filter string to parse. The filter string syntax supports:
- Entity specification:
- attributes: `attribute_name` (default if no prefix is specified)
- metrics: `metrics.metric_name`
- parameters: `params.param_name`
- tags: `tags.tag_name`
- Comparison operators:
- For numeric entities (metrics and numeric attributes): <, <=, >, >=, =, !=
- For string entities (params, tags, string attributes): =, !=, IN, NOT IN
- Multiple conditions can be joined with 'AND'
- String values must be enclosed in single quotes
Example filter strings:
- `creation_time > 100`
- `metrics.rmse > 0.5 AND params.model_type = 'rf'`
- `tags.release IN ('v1.0', 'v1.1')`
- `params.optimizer != 'adam' AND metrics.accuracy >= 0.9`
datasets: List of dictionaries to specify datasets on which to apply metrics filters
For example, a filter string with `metrics.accuracy > 0.9` and dataset with name
"test_dataset" means we will return all logged models with accuracy > 0.9 on the
test_dataset. Metric values from ANY dataset matching the criteria are considered.
If no datasets are specified, then metrics across all datasets are considered in
the filter. The following fields are supported:
dataset_name (str):
Required. Name of the dataset.
dataset_digest (str):
Optional. Digest of the dataset.
max_results: The maximum number of logged models to return.
order_by: List of dictionaries to specify the ordering of the search results. The following
fields are supported:
field_name (str):
Required. Name of the field to order by, e.g. "metrics.accuracy".
ascending (bool):
Optional. Whether the order is ascending or not.
dataset_name (str):
Optional. If ``field_name`` refers to a metric, this field
specifies the name of the dataset associated with the metric. Only metrics
associated with the specified dataset name will be considered for ordering.
This field may only be set if ``field_name`` refers to a metric.
dataset_digest (str):
Optional. If ``field_name`` refers to a metric, this field
specifies the digest of the dataset associated with the metric. Only metrics
associated with the specified dataset name and digest will be considered for
ordering. This field may only be set if ``dataset_name`` is also set.
output_format: The output format of the search results. Supported values are 'pandas'
and 'list'.
Returns:
The search results in the specified output format.
Example:
.. code-block:: python
:test:
import mlflow
class DummyModel(mlflow.pyfunc.PythonModel):
def predict(self, context, model_input: list[str]) -> list[str]:
return model_input
model_info = mlflow.pyfunc.log_model(name="model", python_model=DummyModel())
another_model_info = mlflow.pyfunc.log_model(
name="another_model", python_model=DummyModel()
)
models = mlflow.search_logged_models(output_format="list")
assert [m.name for m in models] == ["another_model", "model"]
models = mlflow.search_logged_models(
filter_string="name = 'another_model'", output_format="list"
)
assert [m.name for m in models] == ["another_model"]
models = mlflow.search_logged_models(
order_by=[{"field_name": "creation_time", "ascending": True}], output_format="list"
)
assert [m.name for m in models] == ["model", "another_model"]
search_model_versions(max_results: int | None = None, filter_string: str | None = None, order_by: list[str] | None = None) -> list[mlflow.entities.model_registry.model_version.ModelVersion]
Search for model versions that satisfy the filter criteria.
.. warning:
The model version search results may not have aliases populated for performance reasons.
Args:
max_results: If passed, specifies the maximum number of models desired. If not
passed, all models will be returned.
filter_string: Filter query string
(e.g., ``"name = 'a_model_name' and tag.key = 'value1'"``),
defaults to searching for all model versions. The following identifiers, comparators,
and logical operators are supported.
Identifiers
- ``name``: model name.
- ``source_path``: model version source path.
- ``run_id``: The id of the mlflow run that generates the model version.
- ``tags.<tag_key>``: model version tag. If ``tag_key`` contains spaces, it must be
wrapped with backticks (e.g., ``"tags.`extra key`"``).
Comparators
- ``=``: Equal to.
- ``!=``: Not equal to.
- ``LIKE``: Case-sensitive pattern match.
- ``ILIKE``: Case-insensitive pattern match.
- ``IN``: In a value list. Only ``run_id`` identifier supports ``IN`` comparator.
Logical operators
- ``AND``: Combines two sub-queries and returns True if both of them are True.
order_by: List of column names with ASC|DESC annotation, to be used for ordering
matching search results.
Returns:
A list of :py:class:`mlflow.entities.model_registry.ModelVersion` objects
that satisfy the search expressions.
.. code-block:: python
:test:
:caption: Example
import mlflow
from sklearn.linear_model import LogisticRegression
for _ in range(2):
with mlflow.start_run():
mlflow.sklearn.log_model(
LogisticRegression(),
name="Cordoba",
registered_model_name="CordobaWeatherForecastModel",
)
# Get all versions of the model filtered by name
filter_string = "name = 'CordobaWeatherForecastModel'"
results = mlflow.search_model_versions(filter_string=filter_string)
print("-" * 80)
for res in results:
print(f"name={res.name}; run_id={res.run_id}; version={res.version}")
# Get the version of the model filtered by run_id
filter_string = "run_id = 'ae9a606a12834c04a8ef1006d0cff779'"
results = mlflow.search_model_versions(filter_string=filter_string)
print("-" * 80)
for res in results:
print(f"name={res.name}; run_id={res.run_id}; version={res.version}")
.. code-block:: text
:caption: Output
--------------------------------------------------------------------------------
name=CordobaWeatherForecastModel; run_id=ae9a606a12834c04a8ef1006d0cff779; version=2
name=CordobaWeatherForecastModel; run_id=d8f028b5fedf4faf8e458f7693dfa7ce; version=1
--------------------------------------------------------------------------------
name=CordobaWeatherForecastModel; run_id=ae9a606a12834c04a8ef1006d0cff779; version=2
search_prompts(filter_string: str | None = None, max_results: int | None = None) -> list[mlflow.entities.model_registry.prompt.Prompt]
Search for prompts in the MLflow Prompt Registry.
This call returns prompt metadata for prompts that have been marked
as prompts (i.e. tagged with `mlflow.prompt.is_prompt=true`). We can
further restrict results via a standard registry filter expression.
Args:
filter_string (Optional[str]):
An additional registry-search expression to apply (e.g.
`"name LIKE 'my_prompt%'"`). For Unity Catalog registries, must include
catalog and schema: "catalog = 'catalog_name' AND schema = 'schema_name'".
max_results (Optional[int]):
The maximum number of prompts to return.
Returns:
A list of :py:class:`Prompt <mlflow.entities.Prompt>` objects representing prompt metadata:
- name: The prompt name
- description: The prompt description
- tags: Prompt-level tags
- creation_timestamp: When the prompt was created
To get the actual prompt template content,
use :py:func:`mlflow.genai.load_prompt()` API with a specific version:
.. code-block:: python
import mlflow
# Search for prompts
prompts = mlflow.genai.search_prompts(filter_string="name LIKE 'greeting%'")
# Get prompts by experiment
prompts = mlflow.genai.search_prompts(filter_string='experiment_id = "1"')
# Get specific version content
for prompt in prompts:
prompt_version = mlflow.genai.load_prompt(prompt.name, version="1")
print(f"Template: {prompt_version.template}")
search_registered_models(max_results: int | None = None, filter_string: str | None = None, order_by: list[str] | None = None) -> list[mlflow.entities.model_registry.registered_model.RegisteredModel]
Search for registered models that satisfy the filter criteria.
Args:
max_results: If passed, specifies the maximum number of models desired. If not
passed, all models will be returned.
filter_string: Filter query string (e.g., "name = 'a_model_name' and tag.key = 'value1'"),
defaults to searching for all registered models. The following identifiers, comparators,
and logical operators are supported.
Identifiers
- "name": registered model name.
- "tags.<tag_key>": registered model tag. If "tag_key" contains spaces, it must be
wrapped with backticks (e.g., "tags.`extra key`").
Comparators
- "=": Equal to.
- "!=": Not equal to.
- "LIKE": Case-sensitive pattern match.
- "ILIKE": Case-insensitive pattern match.
Logical operators
- "AND": Combines two sub-queries and returns True if both of them are True.
order_by: List of column names with ASC|DESC annotation, to be used for ordering
matching search results.
Returns:
A list of :py:class:`mlflow.entities.model_registry.RegisteredModel` objects
that satisfy the search expressions.
.. code-block:: python
:test:
:caption: Example
import mlflow
from sklearn.linear_model import LogisticRegression
with mlflow.start_run():
mlflow.sklearn.log_model(
LogisticRegression(),
name="Cordoba",
registered_model_name="CordobaWeatherForecastModel",
)
mlflow.sklearn.log_model(
LogisticRegression(),
name="Boston",
registered_model_name="BostonWeatherForecastModel",
)
# Get search results filtered by the registered model name
filter_string = "name = 'CordobaWeatherForecastModel'"
results = mlflow.search_registered_models(filter_string=filter_string)
print("-" * 80)
for res in results:
for mv in res.latest_versions:
print(f"name={mv.name}; run_id={mv.run_id}; version={mv.version}")
# Get search results filtered by the registered model name that matches
# prefix pattern
filter_string = "name LIKE 'Boston%'"
results = mlflow.search_registered_models(filter_string=filter_string)
print("-" * 80)
for res in results:
for mv in res.latest_versions:
print(f"name={mv.name}; run_id={mv.run_id}; version={mv.version}")
# Get all registered models and order them by ascending order of the names
results = mlflow.search_registered_models(order_by=["name ASC"])
print("-" * 80)
for res in results:
for mv in res.latest_versions:
print(f"name={mv.name}; run_id={mv.run_id}; version={mv.version}")
.. code-block:: text
:caption: Output
--------------------------------------------------------------------------------
name=CordobaWeatherForecastModel; run_id=248c66a666744b4887bdeb2f9cf7f1c6; version=1
--------------------------------------------------------------------------------
name=BostonWeatherForecastModel; run_id=248c66a666744b4887bdeb2f9cf7f1c6; version=1
--------------------------------------------------------------------------------
name=BostonWeatherForecastModel; run_id=248c66a666744b4887bdeb2f9cf7f1c6; version=1
name=CordobaWeatherForecastModel; run_id=248c66a666744b4887bdeb2f9cf7f1c6; version=1
search_runs(experiment_ids: list[str] | None = None, filter_string: str = '', run_view_type: int = 1, max_results: int = 100000, order_by: list[str] | None = None, output_format: str = 'pandas', search_all_experiments: bool = False, experiment_names: list[str] | None = None) -> Union[list[mlflow.entities.run.Run], ForwardRef('pandas.DataFrame')]
Search for Runs that fit the specified criteria.
Args:
experiment_ids: List of experiment IDs. Search can work with experiment IDs or
experiment names, but not both in the same call. Values other than
``None`` or ``[]`` will result in error if ``experiment_names`` is
also not ``None`` or ``[]``. ``None`` will default to the active
experiment if ``experiment_names`` is ``None`` or ``[]``.
filter_string: Filter query string, defaults to searching all runs.
run_view_type: one of enum values ``ACTIVE_ONLY``, ``DELETED_ONLY``, or ``ALL`` runs
defined in :py:class:`mlflow.entities.ViewType`.
max_results: The maximum number of runs to put in the dataframe. Default is 100,000
to avoid causing out-of-memory issues on the user's machine.
order_by: List of columns to order by (e.g., "metrics.rmse"). The ``order_by`` column
can contain an optional ``DESC`` or ``ASC`` value. The default is ``ASC``.
The default ordering is to sort by ``start_time DESC``, then ``run_id``.
output_format: The output format to be returned. If ``pandas``, a ``pandas.DataFrame``
is returned and, if ``list``, a list of :py:class:`mlflow.entities.Run`
is returned.
search_all_experiments: Boolean specifying whether all experiments should be searched.
Only honored if ``experiment_ids`` is ``[]`` or ``None``.
experiment_names: List of experiment names. Search can work with experiment IDs or
experiment names, but not both in the same call. Values other
than ``None`` or ``[]`` will result in error if ``experiment_ids``
is also not ``None`` or ``[]``. ``None`` will default to the active
experiment if ``experiment_ids`` is ``None`` or ``[]``.
Returns:
If output_format is ``list``: a list of :py:class:`mlflow.entities.Run`. If
output_format is ``pandas``: ``pandas.DataFrame`` of runs, where each metric,
parameter, and tag is expanded into its own column named metrics.*, params.*, or
tags.* respectively. For runs that don't have a particular metric, parameter, or tag,
the value for the corresponding column is (NumPy) ``Nan``, ``None``, or ``None``
respectively.
.. code-block:: python
:test:
:caption: Example
import mlflow
# Create an experiment and log two runs under it
experiment_name = "Social NLP Experiments"
experiment_id = mlflow.create_experiment(experiment_name)
with mlflow.start_run(experiment_id=experiment_id):
mlflow.log_metric("m", 1.55)
mlflow.set_tag("s.release", "1.1.0-RC")
with mlflow.start_run(experiment_id=experiment_id):
mlflow.log_metric("m", 2.50)
mlflow.set_tag("s.release", "1.2.0-GA")
# Search for all the runs in the experiment with the given experiment ID
df = mlflow.search_runs([experiment_id], order_by=["metrics.m DESC"])
print(df[["metrics.m", "tags.s.release", "run_id"]])
print("--")
# Search the experiment_id using a filter_string with tag
# that has a case insensitive pattern
filter_string = "tags.s.release ILIKE '%rc%'"
df = mlflow.search_runs([experiment_id], filter_string=filter_string)
print(df[["metrics.m", "tags.s.release", "run_id"]])
print("--")
# Search for all the runs in the experiment with the given experiment name
df = mlflow.search_runs(experiment_names=[experiment_name], order_by=["metrics.m DESC"])
print(df[["metrics.m", "tags.s.release", "run_id"]])
.. code-block:: text
:caption: Output
metrics.m tags.s.release run_id
0 2.50 1.2.0-GA 147eed886ab44633902cc8e19b2267e2
1 1.55 1.1.0-RC 5cc7feaf532f496f885ad7750809c4d4
--
metrics.m tags.s.release run_id
0 1.55 1.1.0-RC 5cc7feaf532f496f885ad7750809c4d4
--
metrics.m tags.s.release run_id
0 2.50 1.2.0-GA 147eed886ab44633902cc8e19b2267e2
1 1.55 1.1.0-RC 5cc7feaf532f496f885ad7750809c4d4
search_sessions(max_results: 'int' = 100, run_id: 'str | None' = None, model_id: 'str | None' = None, include_spans: 'bool' = True, locations: 'list[str] | None' = None) -> 'list[Session]'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Return complete sessions that match the given search criteria.
A session is a collection of traces that share the same session ID, typically representing
a multi-turn conversation or a series of related interactions. This API retrieves complete
sessions by first identifying unique session IDs from traces, then fetching all traces
belonging to each session in parallel.
Args:
max_results: Maximum number of sessions to return. Default is 100.
run_id: A run id to scope the search. When a trace is created under an active run,
it will be associated with the run and you can filter on the run id to retrieve
traces.
model_id: If specified, search traces associated with the given model ID.
include_spans: If ``True``, include spans in the returned traces. Otherwise, only
the trace metadata is returned. Default is ``True``.
locations: A list of locations to search over. To search over experiments, provide
a list of experiment IDs. To search over UC tables on databricks, provide
a list of locations in the format
`<catalog_name>.<schema_name>[.<table_prefix>]`.
If not provided, the search will be performed across the current active experiment.
Returns:
A list of :py:class:`Session <mlflow.entities.Session>` objects, where each session
contains :py:class:`Trace <mlflow.entities.Trace>` objects that share the same
session ID. Sessions are ordered by the timestamp of their first trace (most recent first).
Each Session object provides convenient access via ``session.id`` and supports
iteration with ``for trace in session``.
.. code-block:: python
:caption: Basic usage - search sessions in an experiment
import mlflow
# Get all sessions from the current experiment
sessions = mlflow.search_sessions()
# Each session provides convenient access to ID and traces
for session in sessions:
print(f"Session {session.id} has {len(session)} traces")
for trace in session:
print(f" Trace: {trace.info.trace_id}")
.. code-block:: python
:caption: Use sessions with evaluation
import mlflow
# Get sessions for evaluation
sessions = mlflow.search_sessions(
locations=["experiment_id"],
max_results=50,
)
# Flatten sessions for evaluation if needed
all_traces = [trace for session in sessions for trace in session]
mlflow.genai.evaluate(data=all_traces)
search_traces(experiment_ids: 'list[str] | None' = None, filter_string: 'str | None' = None, max_results: 'int | None' = None, order_by: 'list[str] | None' = None, extract_fields: 'list[str] | None' = None, run_id: 'str | None' = None, return_type: "Literal['pandas', 'list'] | None" = None, model_id: 'str | None' = None, sql_warehouse_id: 'str | None' = None, include_spans: 'bool' = True, locations: 'list[str] | None' = None, flush: 'bool' = False) -> "'pandas.DataFrame' | list[Trace]"
.. Note:: Parameter ``experiment_ids`` is deprecated. Use ``locations`` instead.
Return traces that match the given list of search expressions within the experiments.
.. note::
If expected number of search results is large, consider using the
`MlflowClient.search_traces` API directly to paginate through the results. This
function returns all results in memory and may not be suitable for large result sets.
Args:
experiment_ids: List of experiment ids to scope the search.
filter_string: A search filter string.
max_results: Maximum number of traces desired. If None, all traces matching the search
expressions will be returned.
order_by: List of order_by clauses.
extract_fields:
.. deprecated:: 3.6.0
This parameter is deprecated and will be removed in a future version.
Specify fields to extract from traces using the format
``"span_name.[inputs|outputs].field_name"`` or ``"span_name.[inputs|outputs]"``.
.. note::
This parameter is only supported when the return type is set to "pandas".
For instance, ``"predict.outputs.result"`` retrieves the output ``"result"`` field from
a span named ``"predict"``, while ``"predict.outputs"`` fetches the entire outputs
dictionary, including keys ``"result"`` and ``"explanation"``.
By default, no fields are extracted into the DataFrame columns. When multiple
fields are specified, each is extracted as its own column. If an invalid field
string is provided, the function silently returns without adding that field's column.
The supported fields are limited to ``"inputs"`` and ``"outputs"`` of spans. If the
span name or field name contains a dot it must be enclosed in backticks. For example:
.. code-block:: python
# span name contains a dot
extract_fields = ["`span.name`.inputs.field"]
# field name contains a dot
extract_fields = ["span.inputs.`field.name`"]
# span name and field name contain a dot
extract_fields = ["`span.name`.inputs.`field.name`"]
run_id: A run id to scope the search. When a trace is created under an active run,
it will be associated with the run and you can filter on the run id to retrieve the
trace. See the example below for how to filter traces by run id.
return_type: The type of the return value. The following return types are supported. If
the pandas library is installed, the default return type is "pandas". Otherwise, the
default return type is "list".
- `"pandas"`: Returns a Pandas DataFrame containing information about traces
where each row represents a single trace and each column represents a field of the
trace e.g. trace_id, spans, etc.
- `"list"`: Returns a list of :py:class:`Trace <mlflow.entities.Trace>` objects.
model_id: If specified, search traces associated with the given model ID.
sql_warehouse_id: DEPRECATED. Use the `MLFLOW_TRACING_SQL_WAREHOUSE_ID` environment
variable instead. The ID of the SQL warehouse to use for
searching traces in inference tables or UC tables. Only used in Databricks.
include_spans: If ``True``, include spans in the returned traces. Otherwise, only
the trace metadata is returned, e.g., trace ID, start time, end time, etc,
without any spans. Default to ``True``.
locations: A list of locations to search over. To search over experiments, provide
a list of experiment IDs. To search over UC tables on databricks, provide
a list of locations in the format
`<catalog_name>.<schema_name>[.<table_prefix>]`.
If not provided, the search will be performed across the current active experiment.
flush: If ``True``, flush any pending async trace writes before searching. Useful
in tests or scripts to ensure all traces are visible. Default to ``False``.
Returns:
Traces that satisfy the search expressions. Either as a list of
:py:class:`Trace <mlflow.entities.Trace>` objects or as a Pandas DataFrame,
depending on the value of the `return_type` parameter.
.. code-block:: python
:test:
:caption: Search traces with extract_fields
import mlflow
with mlflow.start_span(name="span1") as span:
span.set_inputs({"a": 1, "b": 2})
span.set_outputs({"c": 3, "d": 4})
mlflow.search_traces(
extract_fields=["span1.inputs", "span1.outputs", "span1.outputs.c"],
return_type="pandas",
)
.. code-block:: python
:test:
:caption: Search traces with extract_fields and non-dictionary span inputs and outputs
import mlflow
with mlflow.start_span(name="non_dict_span") as span:
span.set_inputs(["a", "b"])
span.set_outputs([1, 2, 3])
mlflow.search_traces(
extract_fields=["non_dict_span.inputs", "non_dict_span.outputs"],
)
.. code-block:: python
:test:
:caption: Search traces by run ID and return as a list of Trace objects
import mlflow
@mlflow.trace
def traced_func(x):
return x + 1
with mlflow.start_run() as run:
traced_func(1)
mlflow.search_traces(run_id=run.info.run_id, return_type="list")
set_active_model(*, name: str | None = None, model_id: str | None = None) -> mlflow.tracking.fluent.ActiveModel
Set the active model with the specified name or model ID, and it will be used for linking
traces that are generated during the lifecycle of the model. The return value can be used as
a context manager within a ``with`` block; otherwise, you must call ``set_active_model()``
to update active model.
Args:
name: The name of the :py:class:`mlflow.entities.LoggedModel` to set as active.
If a LoggedModel with the name does not exist, it will be created under the current
experiment. If multiple LoggedModels with the name exist, the latest one will be
set as active.
model_id: The ID of the :py:class:`mlflow.entities.LoggedModel` to set as active.
If no LoggedModel with the ID exists, an exception will be raised.
Returns:
:py:class:`mlflow.ActiveModel` object that acts as a context manager wrapping the
LoggedModel's state.
.. code-block:: python
:test:
:caption: Example
import mlflow
# Set the active model by name
mlflow.set_active_model(name="my_model")
# Set the active model by model ID
model = mlflow.create_external_model(name="test_model")
mlflow.set_active_model(model_id=model.model_id)
# Use the active model in a context manager
with mlflow.set_active_model(name="new_model"):
print(mlflow.get_active_model_id())
# Traces are automatically linked to the active model
mlflow.set_active_model(name="my_model")
@mlflow.trace
def predict(model_input):
return model_input
predict("abc")
traces = mlflow.search_traces(
model_id=mlflow.get_active_model_id(), return_type="list", flush=True
)
assert len(traces) == 1
set_experiment(experiment_name: str | None = None, experiment_id: str | None = None, trace_location: mlflow.entities.trace_location.UnityCatalog | None = None) -> mlflow.entities.experiment.Experiment
Set the given experiment as the active experiment. The experiment must either be specified by
name via `experiment_name` or by ID via `experiment_id`. The experiment name and ID cannot
both be specified.
.. note::
If the experiment being set by name does not exist, a new experiment will be
created with the given name. After the experiment has been created, it will be set
as the active experiment. On certain platforms, such as Databricks, the experiment name
must be an absolute path, e.g. ``"/Users/<username>/my-experiment"``.
Args:
experiment_name: Case sensitive name of the experiment to be activated.
experiment_id: ID of the experiment to be activated. If an experiment with this ID
does not exist, an exception is thrown.
trace_location: Optional UC trace location used to configure the experiment-derived
tracing destination. Must be an instance of
``mlflow.entities.trace_location.UnityCatalog(...)``.
Returns:
An instance of :py:class:`mlflow.entities.Experiment` representing the new active
experiment.
.. code-block:: python
:test:
:caption: Example
import mlflow
# Set an experiment name, which must be unique and case-sensitive.
experiment = mlflow.set_experiment("Social NLP Experiments")
# Get Experiment Details
print(f"Experiment_id: {experiment.experiment_id}")
print(f"Artifact Location: {experiment.artifact_location}")
print(f"Tags: {experiment.tags}")
print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
.. code-block:: text
:caption: Output
Experiment_id: 1
Artifact Location: file:///.../mlruns/1
Tags: {}
Lifecycle_stage: active
set_experiment_tag(key: str, value: Any) -> None
Set a tag on the current experiment. Value is converted to a string.
Args:
key: Tag name. This string may only contain alphanumerics, underscores (_), dashes (-),
periods (.), spaces ( ), and slashes (/). All backend stores will support keys up to
length 250, but some may support larger keys.
value: Tag value, but will be string-ified if not. All backend stores will support values
up to length 5000, but some may support larger values.
.. code-block:: python
:test:
:caption: Example
import mlflow
with mlflow.start_run():
mlflow.set_experiment_tag("release.version", "2.2.0")
set_experiment_tags(tags: dict[str, typing.Any]) -> None
Set tags for the current active experiment.
Args:
tags: Dictionary containing tag names and corresponding values.
.. code-block:: python
:test:
:caption: Example
import mlflow
tags = {
"engineering": "ML Platform",
"release.candidate": "RC1",
"release.version": "2.2.0",
}
# Set a batch of tags
with mlflow.start_run():
mlflow.set_experiment_tags(tags)
set_logged_model_tags(model_id: str, tags: dict[str, typing.Any]) -> None
Set tags on the specified logged model.
Args:
model_id: ID of the model.
tags: Tags to set on the model.
Returns:
None
Example:
.. code-block:: python
:test:
import mlflow
class DummyModel(mlflow.pyfunc.PythonModel):
def predict(self, context, model_input: list[str]) -> list[str]:
return model_input
model_info = mlflow.pyfunc.log_model(name="model", python_model=DummyModel())
mlflow.set_logged_model_tags(model_info.model_id, {"key": "value"})
model = mlflow.get_logged_model(model_info.model_id)
assert model.tags["key"] == "value"
set_model_version_tag(name: str, version: str | None = None, key: str | None = None, value: Any = None) -> None
Set a tag for the model version.
Args:
name: Registered model name.
version: Registered model version.
key: Tag key to log. key is required.
value: Tag value to log. value is required.
set_prompt_alias(name: str, alias: str, version: int) -> None
Set an alias for a :py:class:`Prompt <mlflow.entities.Prompt>` in the MLflow Prompt Registry.
Args:
name: The name of the prompt.
alias: The alias to set for the prompt.
version: The version of the prompt.
Example:
.. code-block:: python
import mlflow
# Set an alias for the prompt
mlflow.set_prompt_alias(name="my_prompt", version=1, alias="production")
# Load the prompt by alias (use "@" to specify the alias)
prompt = mlflow.load_prompt("prompts:/my_prompt@production")
# Switch the alias to a new version of the prompt
mlflow.set_prompt_alias(name="my_prompt", version=2, alias="production")
# Delete the alias
mlflow.delete_prompt_alias(name="my_prompt", alias="production")
set_registry_uri(uri: str) -> None
Set the registry server URI. This method is especially useful if you have a registry server
that's different from the tracking server.
Args:
uri: An empty string, or a local file path, prefixed with ``file:/``. Data is stored
locally at the provided file (or ``./mlruns`` if empty). An HTTP URI like
``https://my-tracking-server:5000`` or ``http://my-oss-uc-server:8080``. A Databricks
workspace, provided as the string "databricks" or, to use a Databricks CLI
`profile <https://github.com/databricks/databricks-cli#installation>`_,
"databricks://<profileName>".
.. code-block:: python
:caption: Example
import mflow
# Set model registry uri, fetch the set uri, and compare
# it with the tracking uri. They should be different
mlflow.set_registry_uri("sqlite:////tmp/registry.db")
mr_uri = mlflow.get_registry_uri()
print(f"Current registry uri: {mr_uri}")
tracking_uri = mlflow.get_tracking_uri()
print(f"Current tracking uri: {tracking_uri}")
# They should be different
assert tracking_uri != mr_uri
.. code-block:: text
:caption: Output
Current registry uri: sqlite:////tmp/registry.db
Current tracking uri: file:///.../mlruns
set_system_metrics_node_id(node_id)
Set the system metrics node id.
node_id is the identifier of the machine where the metrics are collected. This is useful in
multi-node (distributed training) setup.
set_system_metrics_samples_before_logging(samples)
Set the number of samples before logging system metrics.
Every time `samples` samples have been collected, the system metrics will be logged to mlflow.
By default `samples=1`.
set_system_metrics_sampling_interval(interval)
Set the system metrics sampling interval.
Every `interval` seconds, the system metrics will be collected. By default `interval=10`.
set_tag(key: str, value: Any, synchronous: bool | None = None) -> mlflow.utils.async_logging.run_operations.RunOperations | None
Set a tag under the current run. If no run is active, this method will create a new active
run.
Args:
key: Tag name. This string may only contain alphanumerics, underscores (_), dashes (-),
periods (.), spaces ( ), and slashes (/). All backend stores will support keys up to
length 250, but some may support larger keys.
value: Tag value, but will be string-ified if not. All backend stores will support values
up to length 5000, but some may support larger values.
synchronous: *Experimental* If True, blocks until the tag is logged successfully. If False,
logs the tag asynchronously and returns a future representing the logging operation.
If None, read from environment variable `MLFLOW_ENABLE_ASYNC_LOGGING`, which
defaults to False if not set.
Returns:
When `synchronous=True`, returns None. When `synchronous=False`, returns an
:py:class:`mlflow.utils.async_logging.run_operations.RunOperations` instance that
represents future for logging operation.
.. code-block:: python
:test:
:caption: Example
import mlflow
# Set a tag.
with mlflow.start_run():
mlflow.set_tag("release.version", "2.2.0")
# Set a tag in async fashion.
with mlflow.start_run():
mlflow.set_tag("release.version", "2.2.1", synchronous=False)
set_tags(tags: dict[str, typing.Any], synchronous: bool | None = None) -> mlflow.utils.async_logging.run_operations.RunOperations | None
Log a batch of tags for the current run. If no run is active, this method will create a
new active run.
Args:
tags: Dictionary of tag_name: String -> value: (String, but will be string-ified if
not)
synchronous: *Experimental* If True, blocks until tags are logged successfully. If False,
logs tags asynchronously and returns a future representing the logging operation.
If None, read from environment variable `MLFLOW_ENABLE_ASYNC_LOGGING`, which
defaults to False if not set.
Returns:
When `synchronous=True`, returns None. When `synchronous=False`, returns an
:py:class:`mlflow.utils.async_logging.run_operations.RunOperations` instance that
represents future for logging operation.
.. code-block:: python
:test:
:caption: Example
import mlflow
tags = {
"engineering": "ML Platform",
"release.candidate": "RC1",
"release.version": "2.2.0",
}
# Set a batch of tags
with mlflow.start_run():
mlflow.set_tags(tags)
# Set a batch of tags in async fashion.
with mlflow.start_run():
mlflow.set_tags(tags, synchronous=False)
set_trace_tag(trace_id: 'str', key: 'str', value: 'str')
.. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
Set a tag on the trace with the given trace ID.
The trace can be an active one or the one that has already ended and recorded in the
backend. Below is an example of setting a tag on an active trace. You can replace the
``trace_id`` parameter to set a tag on an already ended trace.
.. code-block:: python
:test:
import mlflow
with mlflow.start_span(name="span") as span:
mlflow.set_trace_tag(span.trace_id, "key", "value")
Args:
trace_id: The ID of the trace to set the tag on.
key: The string key of the tag. Must be at most 250 characters long, otherwise
it will be truncated when stored.
value: The string value of the tag. Must be at most 250 characters long, otherwise
it will be truncated when stored.
set_tracking_uri(uri: str | pathlib.Path) -> None
Set the tracking server URI. This does not affect the
currently active run (if one exists), but takes effect for successive runs.
Args:
uri:
- An empty string, or a local file path, prefixed with ``file:/``. Data is stored
locally at the provided file (or ``./mlruns`` if empty).
- An HTTP URI like ``https://my-tracking-server:5000``.
- A Databricks workspace, provided as the string "databricks" or, to use a Databricks
CLI `profile <https://github.com/databricks/databricks-cli#installation>`_,
"databricks://<profileName>".
- A :py:class:`pathlib.Path` instance
.. code-block:: python
:test:
:caption: Example
import mlflow
mlflow.set_tracking_uri("file:///tmp/my_tracking")
tracking_uri = mlflow.get_tracking_uri()
print(f"Current tracking uri: {tracking_uri}")
.. code-block:: text
:caption: Output
Current tracking uri: file:///tmp/my_tracking
set_workspace(workspace: 'str | None') -> 'None'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Set the active workspace for subsequent MLflow operations.
start_run(run_id: str | None = None, experiment_id: str | None = None, run_name: str | None = None, nested: bool = False, parent_run_id: str | None = None, tags: dict[str, typing.Any] | None = None, description: str | None = None, log_system_metrics: bool | None = None) -> mlflow.tracking.fluent.ActiveRun
Start a new MLflow run, setting it as the active run under which metrics and parameters
will be logged. The return value can be used as a context manager within a ``with`` block;
otherwise, you must call ``end_run()`` to terminate the current run.
If you pass a ``run_id`` or the ``MLFLOW_RUN_ID`` environment variable is set,
``start_run`` attempts to resume a run with the specified run ID and
other parameters are ignored. ``run_id`` takes precedence over ``MLFLOW_RUN_ID``.
If resuming an existing run, the run status is set to ``RunStatus.RUNNING``.
MLflow sets a variety of default tags on the run, as defined in
`MLflow system tags <../../tracking/tracking-api.html#system_tags>`_.
Args:
run_id: If specified, get the run with the specified UUID and log parameters
and metrics under that run. The run's end time is unset and its status
is set to running, but the run's other attributes (``source_version``,
``source_type``, etc.) are not changed.
experiment_id: ID of the experiment under which to create the current run (applicable
only when ``run_id`` is not specified). If ``experiment_id`` argument
is unspecified, will look for valid experiment in the following order:
activated using ``set_experiment``, ``MLFLOW_EXPERIMENT_NAME``
environment variable, ``MLFLOW_EXPERIMENT_ID`` environment variable,
or the default experiment as defined by the tracking server.
run_name: Name of new run, should be a non-empty string. Used only when ``run_id`` is
unspecified. If a new run is created and ``run_name`` is not specified,
a random name will be generated for the run.
nested: Controls whether run is nested in parent run. ``True`` creates a nested run.
parent_run_id: If specified, the current run will be nested under the run with
the specified UUID. The parent run must be in the ACTIVE state.
tags: An optional dictionary of string keys and values to set as tags on the run.
If a run is being resumed, these tags are set on the resumed run. If a new run is
being created, these tags are set on the new run.
description: An optional string that populates the description box of the run.
If a run is being resumed, the description is set on the resumed run.
If a new run is being created, the description is set on the new run.
log_system_metrics: bool, defaults to None. If True, system metrics will be logged
to MLflow, e.g., cpu/gpu utilization. If None, we will check environment variable
`MLFLOW_ENABLE_SYSTEM_METRICS_LOGGING` to determine whether to log system metrics.
System metrics logging is an experimental feature in MLflow 2.8 and subject to change.
Returns:
:py:class:`mlflow.ActiveRun` object that acts as a context manager wrapping the
run's state.
.. code-block:: python
:test:
:caption: Example
import mlflow
# Create nested runs
experiment_id = mlflow.create_experiment("experiment1")
with mlflow.start_run(
run_name="PARENT_RUN",
experiment_id=experiment_id,
tags={"version": "v1", "priority": "P1"},
description="parent",
) as parent_run:
mlflow.log_param("parent", "yes")
with mlflow.start_run(
run_name="CHILD_RUN",
experiment_id=experiment_id,
description="child",
nested=True,
) as child_run:
mlflow.log_param("child", "yes")
print("parent run:")
print(f"run_id: {parent_run.info.run_id}")
print("description: {}".format(parent_run.data.tags.get("mlflow.note.content")))
print("version tag value: {}".format(parent_run.data.tags.get("version")))
print("priority tag value: {}".format(parent_run.data.tags.get("priority")))
print("--")
# Search all child runs with a parent id
query = f"tags.mlflow.parentRunId = '{parent_run.info.run_id}'"
results = mlflow.search_runs(experiment_ids=[experiment_id], filter_string=query)
print("child runs:")
print(results[["run_id", "params.child", "tags.mlflow.runName"]])
# Create a nested run under the existing parent run
with mlflow.start_run(
run_name="NEW_CHILD_RUN",
experiment_id=experiment_id,
description="new child",
parent_run_id=parent_run.info.run_id,
) as child_run:
mlflow.log_param("new-child", "yes")
.. code-block:: text
:caption: Output
parent run:
run_id: 8979459433a24a52ab3be87a229a9cdf
description: starting a parent for experiment 7
version tag value: v1
priority tag value: P1
--
child runs:
run_id params.child tags.mlflow.runName
0 7d175204675e40328e46d9a6a5a7ee6a yes CHILD_RUN
start_span(name: 'str' = 'span', span_type: 'str | None' = 'UNKNOWN', attributes: 'dict[str, Any] | None' = None, trace_destination: 'TraceLocationBase | None' = None, log_level: 'SpanLogLevel | str | None' = None, run_id: 'str | None' = None, links: 'list[Link] | None' = None) -> 'Generator[LiveSpan, None, None]'
Context manager to create a new span and start it as the current span in the context.
This context manager automatically manages the span lifecycle and parent-child relationships.
The span will be ended when the context manager exits. Any exception raised within the
context manager will set the span status to ``ERROR``, and detailed information such as
exception message and stacktrace will be recorded to the ``attributes`` field of the span.
New spans can be created within the context manager, then they will be assigned as child
spans.
.. code-block:: python
:test:
import mlflow
with mlflow.start_span("my_span") as span:
x = 1
y = 2
span.set_inputs({"x": x, "y": y})
z = x + y
span.set_outputs(z)
span.set_attribute("key", "value")
# do something
When this context manager is used in the top-level scope, i.e. not within another span context,
the span will be treated as a root span. The root span doesn't have a parent reference and
**the entire trace will be logged when the root span is ended**.
.. tip::
If you want more explicit control over the trace lifecycle, you can use
the `mlflow.start_span_no_context()` API. It provides lower
level to start spans and control the parent-child relationships explicitly.
However, it is generally recommended to use this context manager as long as it satisfies
your requirements, because it requires less boilerplate code and is less error-prone.
.. note::
The context manager doesn't propagate the span context across threads by default. see
`Multi Threading <https://mlflow.org/docs/latest/tracing/api/manual-instrumentation#multi-threading>`_
for how to propagate the span context across threads.
Args:
name: The name of the span.
span_type: The type of the span. Can be either a string or
a :py:class:`SpanType <mlflow.entities.SpanType>` enum value
attributes: A dictionary of attributes to set on the span.
trace_destination: The destination to log the trace to, such as MLflow Experiment. If
not provided, the destination will be an active MLflow experiment or an destination
set by the :py:func:`mlflow.tracing.set_destination` function. This parameter
should only be used for root span and setting this for non-root spans will be
ignored with a warning.
log_level: Optional severity level to attach to the span. Accepts a
:py:class:`SpanLogLevel <mlflow.entities.SpanLogLevel>` or its name
(e.g. ``"INFO"``, ``"DEBUG"``). If not provided, the span level is
resolved from the span type at end time.
run_id: The ID of the MLflow run to associate with the trace. This parameter is
only applied when creating a root span. If provided without an explicit
`trace_destination`, the trace will be logged to the run's experiment. If an
active MLflow run is already set via `mlflow.start_run()`, this parameter takes
precedence over the active run.
links: A list of :py:class:`Link <mlflow.entities.Link>` objects to associate with
the span.
Returns:
Yields an :py:class:`mlflow.entities.Span` that represents the created span.
start_span_no_context(name: 'str', span_type: 'str' = 'UNKNOWN', parent_span: 'LiveSpan | None' = None, inputs: 'Any | None' = None, attributes: 'dict[str, str] | None' = None, tags: 'dict[str, str] | None' = None, metadata: 'dict[str, str] | None' = None, experiment_id: 'str | None' = None, start_time_ns: 'int | None' = None, log_level: 'SpanLogLevel | str | None' = None, links: 'list[Link] | None' = None) -> 'LiveSpan'
Start a span without attaching it to the global tracing context.
This is useful when you want to create a span without automatically linking
with a parent span and instead manually manage the parent-child relationships.
The span started with this function must be ended manually using the
`end()` method of the span object.
Args:
name: The name of the span.
span_type: The type of the span. Can be either a string or
a :py:class:`SpanType <mlflow.entities.SpanType>` enum value
parent_span: The parent span to link with. If None, the span will be treated as a root span.
inputs: The input data for the span.
attributes: A dictionary of attributes to set on the span.
tags: A dictionary of tags to set on the trace.
metadata: A dictionary of metadata to set on the trace.
experiment_id: The experiment ID to associate with the trace. If not provided,
the current active experiment will be used.
start_time_ns: The start time of the span in nanoseconds. If not provided,
the current time will be used.
log_level: Optional severity level to attach to the span. Accepts a
:py:class:`SpanLogLevel <mlflow.entities.SpanLogLevel>` or its name
(e.g. ``"INFO"``, ``"DEBUG"``). If not provided, the span level is
resolved from the span type at end time.
links: A list of :py:class:`Link <mlflow.entities.Link>` objects to associate with
the span.
Returns:
A :py:class:`mlflow.entities.Span` that represents the created span.
Example:
.. code-block:: python
:test:
import mlflow
root_span = mlflow.start_span_no_context("my_trace")
# Create a child span
child_span = mlflow.start_span_no_context(
"child_span",
# Manually specify the parent span
parent_span=root_span,
)
# Do something...
child_span.end()
root_span.end()
test(fn: 'Callable[_P, _R] | None' = None) -> 'Callable[_P, _R]'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Mark a test function for the MLflow pytest plugin.
Supports both bare ``@mlflow.test`` and ``@mlflow.test()``. Raises at test
time if the plugin is not enabled, instead of silently running the test
without MLflow run/trace management.
trace(func: 'Callable[..., Any] | None' = None, name: 'str | None' = None, span_type: 'str' = 'UNKNOWN', attributes: 'dict[str, Any] | None' = None, output_reducer: 'Callable[[list[Any]], Any] | None' = None, trace_destination: 'TraceLocationBase | None' = None, sampling_ratio_override: 'float | None' = None, log_level: 'SpanLogLevel | str | None' = None, links: 'list[Link] | None' = None) -> 'Callable[..., Any]'
A decorator that creates a new span for the decorated function.
When you decorate a function with this :py:func:`@mlflow.trace() <trace>` decorator,
a span will be created for the scope of the decorated function. The span will automatically
capture the input and output of the function. When it is applied to a method, it doesn't
capture the `self` argument. Any exception raised within the function will set the span
status to ``ERROR`` and detailed information such as exception message and stacktrace
will be recorded to the ``attributes`` field of the span.
For example, the following code will yield a span with the name ``"my_function"``,
capturing the input arguments ``x`` and ``y``, and the output of the function.
.. code-block:: python
:test:
import mlflow
@mlflow.trace
def my_function(x, y):
return x + y
This is equivalent to doing the following using the :py:func:`mlflow.start_span` context
manager, but requires less boilerplate code.
.. code-block:: python
:test:
import mlflow
def my_function(x, y):
return x + y
with mlflow.start_span("my_function") as span:
x = 1
y = 2
span.set_inputs({"x": x, "y": y})
result = my_function(x, y)
span.set_outputs({"output": result})
The @mlflow.trace decorator currently support the following types of functions:
.. list-table:: Supported Function Types
:widths: 20 30
:header-rows: 1
* - Function Type
- Supported
* - Sync
- ✅
* - Async
- ✅ (>= 2.16.0)
* - Generator
- ✅ (>= 2.20.2)
* - Async Generator
- ✅ (>= 2.20.2)
* - ClassMethod
- ✅ (>= 3.0.0)
* - StaticMethod
- ✅ (>= 3.0.0)
For more examples of using the @mlflow.trace decorator, including streaming/async
handling, see the `MLflow Tracing documentation <https://www.mlflow.org/docs/latest/tracing/api/manual-instrumentation#decorator>`_.
.. tip::
The @mlflow.trace decorator is useful when you want to trace a function defined by
yourself. However, you may also want to trace a function in external libraries. In
such case, you can use this ``mlflow.trace()`` function to directly wrap the function,
instead of using as the decorator. This will create the exact same span as the
one created by the decorator i.e. captures information from the function call.
.. code-block:: python
:test:
import math
import mlflow
mlflow.trace(math.factorial)(5)
Args:
func: The function to be decorated. Must **not** be provided when using as a decorator.
name: The name of the span. If not provided, the name of the function will be used.
span_type: The type of the span. Can be either a string or a
:py:class:`SpanType <mlflow.entities.SpanType>` enum value.
attributes: A dictionary of attributes to set on the span.
output_reducer: A function that reduces the outputs of the generator function into a
single value to be set as the span output.
trace_destination: The destination to log the trace to, such as MLflow Experiment. If
not provided, the destination will be an active MLflow experiment or an destination
set by the :py:func:`mlflow.tracing.set_destination` function. This parameter
should only be used for root span and setting this for non-root spans will be
ignored with a warning.
sampling_ratio_override: The sampling ratio override for this specific function. Must be
between 0.0 and 1.0. If provided, this overrides the global
``MLFLOW_TRACE_SAMPLING_RATIO`` setting. A value of 1.0 means all traces are sampled,
0.5 means 50% are sampled, and 0.0 means no traces are sampled. If not provided (None),
the global sampling ratio is used. Note: This only applies to root spans; nested calls
always trace if the parent is traced.
log_level: Optional severity level to attach to the span. Accepts a
:py:class:`SpanLogLevel <mlflow.entities.SpanLogLevel>` or its name
(e.g. ``"INFO"``, ``"DEBUG"``). If not provided, the span level is
resolved from the span type at end time.
links: A list of :py:class:`Link <mlflow.entities.Link>` objects to associate with the span.
update_assessment(trace_id: str, assessment_id: str, assessment: mlflow.entities.assessment.Assessment) -> mlflow.entities.assessment.Assessment
Updates an existing expectation (ground truth) in a Trace.
Args:
trace_id: The ID of the trace.
assessment_id: The ID of the expectation or feedback assessment to update.
assessment: The updated assessment.
Returns:
:py:class:`~mlflow.entities.Assessment`: The updated feedback or expectation assessment.
Example:
The following code updates an existing expectation with a new value.
To update other fields, provide the corresponding parameters.
.. code-block:: python
import mlflow
from mlflow.entities import Expectation, ExpectationValue
# Create an expectation with value 42.
response = mlflow.log_assessment(
trace_id="1234",
assessment=Expectation(name="expected_answer", value=42),
)
assessment_id = response.assessment_id
# Update the expectation with a new value 43.
mlflow.update_assessment(
trace_id="1234",
assessment_id=assessment.assessment_id,
assessment=Expectation(name="expected_answer", value=43),
)
update_current_trace(tags: 'dict[str, str] | None' = None, metadata: 'dict[str, str] | None' = None, client_request_id: 'str | None' = None, request_preview: 'str | None' = None, response_preview: 'str | None' = None, state: 'TraceState | str | None' = None, model_id: 'str | None' = None, session_id: 'str | None' = None, user: 'str | None' = None)
Update the current active trace with the given options.
Args:
tags: A dictionary of tags to update the trace with Tags are designed for mutable values,
that can be updated after the trace is created via MLflow UI or API.
metadata: A dictionary of metadata to update the trace with. Metadata cannot be updated
once the trace is logged. It is suitable for recording immutable values like the
git hash of the application version that produced the trace.
client_request_id: Client supplied request ID to associate with the trace. This is
useful for linking the trace back to a specific request in your application or
external system. If None, the client request ID is not updated.
request_preview: A preview of the request to be shown in the Trace list view in the UI.
By default, MLflow will truncate the trace request naively by limiting the length.
This parameter allows you to specify a custom preview string.
response_preview: A preview of the response to be shown in the Trace list view in the UI.
By default, MLflow will truncate the trace response naively by limiting the length.
This parameter allows you to specify a custom preview string.
state: The state to set on the trace. Can be a TraceState enum value or string.
Only "OK" and "ERROR" are allowed. This overrides the overall trace state without
affecting the status of the current span.
model_id: The ID of the model to associate with the trace. If not set, the active
model ID is associated with the trace.
session_id: Session ID to associate with the trace. Stored as metadata under the
``mlflow.trace.session`` key.
user: User identifier to associate with the trace. Stored as metadata under the
``mlflow.trace.user`` key.
Example:
You can use this function either within a function decorated with ``@mlflow.trace`` or
within the scope of the `with mlflow.start_span` context manager. If there is no active
trace found, this function will raise an exception.
Using within a function decorated with `@mlflow.trace`:
.. code-block:: python
@mlflow.trace
def my_func(x):
mlflow.update_current_trace(tags={"fruit": "apple"}, client_request_id="req-12345")
return x + 1
Using within the ``with mlflow.start_span`` context manager:
.. code-block:: python
with mlflow.start_span("span"):
mlflow.update_current_trace(tags={"fruit": "apple"}, client_request_id="req-12345")
Updating user, session, and source information of the trace:
.. code-block:: python
mlflow.update_current_trace(
session_id="session-4f855da00427",
user="user-id-cc156f29bcfb",
metadata={
"mlflow.source.name": "inference.py",
"mlflow.source.git.commit": "1234567890",
"mlflow.source.git.repoURL": "https://github.com/mlflow/mlflow",
},
)
Updating request preview:
.. code-block:: python
import mlflow
import openai
@mlflow.trace
def predict(messages: list[dict]) -> str:
# Customize the request preview to show the first and last messages
custom_preview = f"{messages[0]['content'][:10]} ... {messages[-1]['content'][:10]}"
mlflow.update_current_trace(request_preview=custom_preview)
# Call the model
response = openai.chat.completions.create(
model="o4-mini",
messages=messages,
)
return response.choices[0].message.content
messages = [
{"role": "user", "content": "Hi, how are you?"},
{"role": "assistant", "content": "I'm good, thank you!"},
{"role": "user", "content": "What's your name?"},
# ... (long message history)
{"role": "assistant", "content": "Bye!"},
]
predict(messages)
# The request preview rendered in the UI will be:
# "Hi, how are you? ... Bye!"
update_workspace(name: 'str', description: 'str | None' = None, default_artifact_root: 'str | None' = None, trace_archival_config: 'TraceArchivalConfig | None' = None) -> 'Workspace'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Update metadata for an existing workspace.
Args:
name: The name of the workspace to update.
description: New description, or ``None`` to leave unchanged.
default_artifact_root: New artifact root URI, empty string to clear, or ``None``.
trace_archival_config: Optional archival settings; use ``""`` to clear, ``None`` to keep.
Returns:
The updated workspace.
Raises:
MlflowException: If the workspace does not exist or no artifact root available.
validate_evaluation_results(validation_thresholds: dict[str, mlflow.models.evaluation.validation.MetricThreshold], candidate_result: mlflow.models.evaluation.base.EvaluationResult, baseline_result: mlflow.models.evaluation.base.EvaluationResult | None = None)
Validate the evaluation result from one model (candidate) against another
model (baseline). If the candidate results do not meet the validation
thresholds, an ModelValidationFailedException will be raised.
.. note::
This API is a replacement for the deprecated model validation
functionality in the :py:func:`mlflow.evaluate` API.
Args:
validation_thresholds: A dictionary of metric name to
:py:class:`mlflow.models.MetricThreshold` used for model validation.
Each metric name must either be the name of a builtin metric or the
name of a metric defined in the ``extra_metrics`` parameter.
candidate_result: The evaluation result of the candidate model.
Returned by the :py:func:`mlflow.evaluate` API.
baseline_result: The evaluation result of the baseline model.
Returned by the :py:func:`mlflow.evaluate` API.
If set to None, the candidate model result will be
compared against the threshold values directly.
Code Example:
.. code-block:: python
:caption: Example of Model Validation
import mlflow
from mlflow.models import MetricThreshold
thresholds = {
"accuracy_score": MetricThreshold(
# accuracy should be >=0.8
threshold=0.8,
# accuracy should be at least 5 percent greater than baseline model accuracy
min_absolute_change=0.05,
# accuracy should be at least 0.05 greater than baseline model accuracy
min_relative_change=0.05,
greater_is_better=True,
),
}
# Get evaluation results for the candidate model
candidate_result = mlflow.evaluate(
model="<YOUR_CANDIDATE_MODEL_URI>",
data=eval_dataset,
targets="ground_truth",
model_type="classifier",
)
# Get evaluation results for the baseline model
baseline_result = mlflow.evaluate(
model="<YOUR_BASELINE_MODEL_URI>",
data=eval_dataset,
targets="ground_truth",
model_type="classifier",
)
# Validate the results
mlflow.validate_evaluation_results(
thresholds,
candidate_result,
baseline_result,
)
See `the Model Validation documentation
<../../models/index.html#performing-model-validation>`_ for more details.
DATA
__all__ = ['MlflowException', 'set_experiment', 'set_tracking_uri', 'g...
VERSION
3.15.0
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\__init__.py
mlflow.models
Python Library Documentation: package mlflow.models in mlflow
NAME
mlflow.models
DESCRIPTION
The ``mlflow.models`` module provides an API for saving machine learning models in
"flavors" that can be understood by different downstream tools.
The built-in flavors are:
- :py:mod:`mlflow.catboost`
- :py:mod:`mlflow.dspy`
- :py:mod:`mlflow.h2o`
- :py:mod:`mlflow.langchain`
- :py:mod:`mlflow.lightgbm`
- :py:mod:`mlflow.llama_index`
- :py:mod:`mlflow.onnx`
- :py:mod:`mlflow.openai`
- :py:mod:`mlflow.paddle`
- :py:mod:`mlflow.pmdarima`
- :py:mod:`mlflow.prophet`
- :py:mod:`mlflow.pyfunc`
- :py:mod:`mlflow.pyspark.ml`
- :py:mod:`mlflow.pytorch`
- :py:mod:`mlflow.sklearn`
- :py:mod:`mlflow.spacy`
- :py:mod:`mlflow.spark`
- :py:mod:`mlflow.statsmodels`
- :py:mod:`mlflow.tensorflow`
- :py:mod:`mlflow.transformers`
- :py:mod:`mlflow.xgboost`
For details, see `MLflow Models guide <https://mlflow.org/docs/latest/ml/model/>`_.
PACKAGE CONTENTS
auth_policy
cli
container (package)
dependencies_schemas
display_utils
docker_utils
evaluation (package)
flavor_backend
flavor_backend_registry
model
model_config
notebook_resources (package)
python_api
rag_signatures
resources
signature
utils
wheeled_model
CLASSES
abc.ABC(builtins.object)
mlflow.models.resources.Resource
builtins.object
mlflow.models.evaluation.base.EvaluationArtifact
mlflow.models.evaluation.base.EvaluationMetric
mlflow.models.evaluation.base.EvaluationResult
mlflow.models.evaluation.validation.MetricThreshold
mlflow.models.flavor_backend.FlavorBackend
mlflow.models.model.Model
mlflow.models.model_config.ModelConfig
mlflow.models.signature.ModelSignature
enum.Enum(builtins.object)
mlflow.models.resources.ResourceType
class EvaluationArtifact(builtins.object)
| EvaluationArtifact(uri, content=None)
|
| A model evaluation artifact containing an artifact uri and content.
|
| Methods defined here:
|
| __init__(self, uri, content=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| content
| The content of the artifact (representation varies)
|
| uri
| The URI of the artifact
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset({'_load_content_from_file', '_save'})
class EvaluationMetric(builtins.object)
| EvaluationMetric(eval_fn, name, greater_is_better, long_name=None, version=None, metric_details=None, metric_metadata=None, genai_metric_args=None)
|
| An evaluation metric.
|
| Args:
| eval_fn: A function that computes the metric with the following signature:
|
| .. code-block:: python
|
| def eval_fn(
| predictions: pandas.Series,
| targets: pandas.Series,
| metrics: Dict[str, MetricValue],
| **kwargs,
| ) -> Union[float, MetricValue]:
| """
| Args:
| predictions: A pandas Series containing the predictions made by the model.
| targets: (Optional) A pandas Series containing the corresponding labels
| for the predictions made on that input.
| metrics: (Optional) A dictionary containing the metrics calculated by the
| default evaluator. The keys are the names of the metrics and the values
| are the metric values. To access the MetricValue for the metrics
| calculated by the system, make sure to specify the type hint for this
| parameter as Dict[str, MetricValue]. Refer to the DefaultEvaluator
| behavior section for what metrics will be returned based on the type of
| model (i.e. classifier or regressor).
| kwargs: Includes a list of args that are used to compute the metric. These
| args could be information coming from input data, model outputs,
| other metrics, or parameters specified in the `evaluator_config`
| argument of the `mlflow.evaluate` API.
|
| Returns: MetricValue with per-row scores, per-row justifications, and aggregate
| results.
| """
| ...
|
| name: The name of the metric.
| greater_is_better: Whether a greater value of the metric is better.
| long_name: (Optional) The long name of the metric. For example,
| ``"root_mean_squared_error"`` for ``"mse"``.
| version: (Optional) The metric version. For example ``v1``.
| metric_details: (Optional) A description of the metric and how it is calculated.
| metric_metadata: (Optional) A dictionary containing metadata for the metric.
| genai_metric_args: (Optional) A dictionary containing arguments specified by users
| when calling make_genai_metric or make_genai_metric_from_prompt. Those args
| are persisted so that we can deserialize the same metric object later.
|
| Methods defined here:
|
| __init__(self, eval_fn, name, greater_is_better, long_name=None, version=None, metric_details=None, metric_metadata=None, genai_metric_args=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| __str__(self)
| Return str(self).
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class EvaluationResult(builtins.object)
| EvaluationResult(metrics, artifacts, run_id=None)
|
| Represents the model evaluation outputs of a `mlflow.evaluate()` API call, containing
| both scalar metrics and output artifacts such as performance plots.
|
| Methods defined here:
|
| __init__(self, metrics, artifacts, run_id=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| save(self, path)
| Write the evaluation results to the specified local filesystem path
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| load(path)
| Load the evaluation results from the specified local filesystem path
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| artifacts
| A dictionary mapping standardized artifact names (e.g. "roc_data") to
| artifact content and location information
|
| metrics
| A dictionary mapping scalar metric names to scalar metric values
|
| run_id
| The ID of the MLflow Run to which the evaluation results were logged.
|
| tables
| A dictionary mapping standardized artifact names (e.g. "eval_results_table") to
| corresponding table content as pandas DataFrame.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class FlavorBackend(builtins.object)
| FlavorBackend(config, **kwargs)
|
| Abstract class for Flavor Backend.
| This class defines the API interface for local model deployment of MLflow model flavors.
|
| Methods defined here:
|
| __init__(self, config, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| build_image(self, model_uri, image_name, install_java=False, install_mlflow=False, mlflow_home=None, base_image=None)
|
| can_build_image(self)
| Returns:
| True if this flavor has a `build_image` method defined for building a docker
| container capable of serving the model, False otherwise.
|
| can_score_model(self)
| Check whether this flavor backend can be deployed in the current environment.
|
| Returns:
| True if this flavor backend can be applied in the current environment.
|
| generate_dockerfile(self, model_uri, output_dir, install_java=False, install_mlflow=False, mlflow_home=None, base_image=None)
|
| predict(self, model_uri, input_path, output_path, content_type)
| Generate predictions using a saved MLflow model referenced by the given URI.
| Input and output are read from and written to a file or stdin / stdout.
|
| Args:
| model_uri: URI pointing to the MLflow model to be used for scoring.
| input_path: Path to the file with input data. If not specified, data is read from
| stdin.
| output_path: Path to the file with output predictions. If not specified, data is
| written to stdout.
| content_type: Specifies the input format. Can be one of {``json``, ``csv``}
|
| prepare_env(self, model_uri, capture_output=False)
| Performs any preparation necessary to predict or serve the model, for example
| downloading dependencies or initializing a conda environment. After preparation,
| calling predict or serve should be fast.
|
| serve(self, model_uri, port, host, timeout, synchronous=True, stdout=None, stderr=None)
| Serve the specified MLflow model locally.
|
| Args:
| model_uri: URI pointing to the MLflow model to be used for scoring.
| port: Port to use for the model deployment.
| host: Host to use for the model deployment. Defaults to ``localhost``.
| timeout: Timeout in seconds to serve a request. Defaults to 60.
| synchronous: If True, wait until server process exit and return 0, if process exit
| with non-zero return code, raise exception.
| If False, return the server process `Popen` instance immediately.
| stdout: Redirect server stdout
| stderr: Redirect server stderr
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __metaclass__ = <class 'abc.ABCMeta'>
| Metaclass for defining Abstract Base Classes (ABCs).
|
| Use this metaclass to create an ABC. An ABC can be subclassed
| directly, and then acts as a mix-in class. You can also register
| unrelated concrete classes (even built-in classes) and unrelated
| ABCs as 'virtual subclasses' -- these and their descendants will
| be considered subclasses of the registering ABC by the built-in
| issubclass() function, but the registering ABC won't show up in
| their MRO (Method Resolution Order) nor will method
| implementations defined by the registering ABC be callable (not
| even via super()).
class MetricThreshold(builtins.object)
| MetricThreshold(threshold=None, min_absolute_change=None, min_relative_change=None, greater_is_better=None)
|
| This class allows you to define metric thresholds for model validation.
| Allowed thresholds are: threshold, min_absolute_change, min_relative_change.
|
| Args:
| threshold: (Optional) A number representing the value threshold for the metric.
|
| - If greater is better for the metric, the metric value has to be
| >= threshold to pass validation.
| - Otherwise, the metric value has to be <= threshold to pass the validation.
|
| min_absolute_change: (Optional) A positive number representing the minimum absolute
| change required for candidate model to pass validation with
| the baseline model.
|
| - If greater is better for the metric, metric value has to be
| >= baseline model metric value + min_absolute_change to pass the validation.
| - Otherwise, metric value has to be <= baseline model metric value - min_absolute_change
| to pass the validation.
|
| min_relative_change: (Optional) A floating point number between 0 and 1 representing
| the minimum relative change (in percentage of
| baseline model metric value) for candidate model
| to pass the comparison with the baseline model.
|
| - If greater is better for the metric, metric value has to be
| >= baseline model metric value * (1 + min_relative_change)
| - Otherwise, metric value has to be
| <= baseline model metric value * (1 - min_relative_change)
| - Note that if the baseline model metric value is equal to 0, the
| threshold falls back performing a simple verification that the
| candidate metric value is better than the baseline metric value,
| i.e. metric value >= baseline model metric value + 1e-10 if greater
| is better; metric value <= baseline model metric value - 1e-10 if
| lower is better.
|
| greater_is_better: A required boolean representing whether greater value is
| better for the metric.
|
| Methods defined here:
|
| __init__(self, threshold=None, min_absolute_change=None, min_relative_change=None, greater_is_better=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| __str__(self)
| Returns a human-readable string consisting of all specified thresholds.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| greater_is_better
| Boolean value representing whether greater value is better for the metric.
|
| min_absolute_change
| Value of the minimum absolute change required to pass model comparison with baseline model.
|
| min_relative_change
| Float value of the minimum relative change required to pass model comparison with
| baseline model.
|
| threshold
| Value of the threshold.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class Model(builtins.object)
| Model(artifact_path=None, run_id=None, utc_time_created=None, flavors=None, signature=None, saved_input_example_info: dict[str, typing.Any] | None = None, model_uuid: Union[str, Callable[[], str], NoneType] = <function Model.<lambda> at 0x0000025F83440B80>, mlflow_version: str | None = '3.15.0', metadata: dict[str, typing.Any] | None = None, model_size_bytes: int | None = None, resources: str | list[mlflow.models.resources.Resource] | None = None, env_vars: list[str] | None = None, auth_policy: mlflow.models.auth_policy.AuthPolicy | None = None, model_id: str | None = None, prompts: list[str] | None = None, **kwargs)
|
| An MLflow Model that can support multiple model flavors. Provides APIs for implementing
| new Model flavors.
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, artifact_path=None, run_id=None, utc_time_created=None, flavors=None, signature=None, saved_input_example_info: dict[str, typing.Any] | None = None, model_uuid: Union[str, Callable[[], str], NoneType] = <function Model.<lambda> at 0x0000025F83440B80>, mlflow_version: str | None = '3.15.0', metadata: dict[str, typing.Any] | None = None, model_size_bytes: int | None = None, resources: str | list[mlflow.models.resources.Resource] | None = None, env_vars: list[str] | None = None, auth_policy: mlflow.models.auth_policy.AuthPolicy | None = None, model_id: str | None = None, prompts: list[str] | None = None, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __str__(self)
| Return str(self).
|
| add_flavor(self, name, **params) -> 'Model'
| Add an entry for how to serve the model in a given format.
|
| get_input_schema(self)
| Retrieves the input schema of the Model iff the model was saved with a schema definition.
|
| get_model_info(self, logged_model: mlflow.entities.logged_model.LoggedModel | None = None) -> mlflow.models.model.ModelInfo
| Create a :py:class:`ModelInfo <mlflow.models.model.ModelInfo>` instance that contains the
| model metadata.
|
| get_output_schema(self)
| Retrieves the output schema of the Model iff the model was saved with a schema definition.
|
| get_params_schema(self)
| Retrieves the parameters schema of the Model iff the model was saved with a schema
| definition.
|
| get_serving_input(self, path: str) -> str | None
| Load serving input example from a model directory. Returns None if there is no serving input
| example.
|
| Args:
| path: Path to the model directory.
|
| Returns:
| Serving input example or None if the model has no serving input example.
|
| get_tags_dict(self) -> dict[str, typing.Any]
|
| load_input_example(self, path: str | None = None) -> str | None
| Load the input example saved along a model. Returns None if there is no example metadata
| (i.e. the model was saved without example). Raises FileNotFoundError if there is model
| metadata but the example file is missing.
|
| Args:
| path: Model or run URI, or path to the `model` directory.
| e.g. models://<model_name>/<model_version>, runs:/<run_id>/<artifact_path>
| or /path/to/model
|
| Returns:
| Input example (NumPy ndarray, SciPy csc_matrix, SciPy csr_matrix,
| pandas DataFrame, dict) or None if the model has no example.
|
| load_input_example_params(self, path: str)
| Load the params of input example saved along a model. Returns None if there are no params in
| the input_example.
|
| Args:
| path: Path to the model directory.
|
| Returns:
| params (dict) or None if the model has no params.
|
| save(self, path) -> None
| Write the model as a local YAML file.
|
| to_dict(self) -> dict[str, typing.Any]
| Serialize the model to a dictionary.
|
| to_json(self) -> str
| Write the model as json.
|
| to_yaml(self, stream=None) -> str
| Write the model as yaml string.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dict(model_dict) -> 'Model'
| Load a model from its YAML representation.
|
| load(path) -> 'Model'
| Load a model from its YAML representation.
|
| Args:
| path: A local filesystem path or URI referring to the MLmodel YAML file
| representation of the Model object or to the directory containing
| the MLmodel YAML file representation.
|
| Returns:
| An instance of Model.
|
| .. code-block:: python
| :caption: example
|
| from mlflow.models import Model
|
| # Load the Model object from a local MLmodel file
| model1 = Model.load("~/path/to/my/MLmodel")
|
| # Load the Model object from a remote model directory
| model2 = Model.load("s3://mybucket/path/to/my/model")
|
| log(artifact_path, flavor, registered_model_name=None, await_registration_for=300, metadata=None, run_id=None, resources=None, auth_policy=None, prompts=None, name: str | None = None, model_type: str | None = None, params: dict[str, typing.Any] | None = None, tags: dict[str, typing.Any] | None = None, step: int = 0, model_id: str | None = None, **kwargs) -> mlflow.models.model.ModelInfo
| Log model using supplied flavor module. If no run is active, this method will create a new
| active run.
|
| Args:
| artifact_path: Deprecated. Use `name` instead.
| flavor: Flavor module to save the model with. The module must have
| the ``save_model`` function that will persist the model as a valid
| MLflow model.
| registered_model_name: If given, create a model version under
| ``registered_model_name``, also creating a registered model if
| one with the given name does not exist.
| await_registration_for: Number of seconds to wait for the model version to finish
| being created and is in ``READY`` status. By default, the
| function waits for five minutes. Specify 0 or None to skip
| waiting.
| metadata: {{ metadata }}
| run_id: The run ID to associate with this model.
| resources: {{ resources }}
| auth_policy: {{ auth_policy }}
| prompts: {{ prompts }}
| name: The name of the model.
| model_type: {{ model_type }}
| params: {{ params }}
| tags: {{ tags }}
| step: {{ step }}
| model_id: {{ model_id }}
| kwargs: Extra args passed to the model flavor.
|
| Returns:
| A :py:class:`ModelInfo <mlflow.models.model.ModelInfo>` instance that contains the
| metadata of the logged model.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| auth_policy
| An optional dictionary that contains the auth policy required to serve the model.
|
| :getter: Retrieves the auth_policy required to serve the model
| :setter: Sets the auth_policy required to serve the model
| :type: Dict[str, dict]
|
| env_vars
|
| metadata
| Custom metadata dictionary passed to the model and stored in the MLmodel file.
|
| :getter: Retrieves custom metadata that have been applied to a model instance.
| :setter: Sets a dictionary of custom keys and values to be included with the model instance
| :type: Optional[Dict[str, Any]]
|
| Returns:
| A Dictionary of user-defined metadata iff defined.
|
| .. code-block:: python
| :caption: Example
|
| # Create and log a model with metadata to the Model Registry
| from sklearn import datasets
| from sklearn.ensemble import RandomForestClassifier
| import mlflow
| from mlflow.models import infer_signature
|
| with mlflow.start_run():
| iris = datasets.load_iris()
| clf = RandomForestClassifier()
| clf.fit(iris.data, iris.target)
| signature = infer_signature(iris.data, iris.target)
| mlflow.sklearn.log_model(
| clf,
| name="iris_rf",
| signature=signature,
| registered_model_name="model-with-metadata",
| metadata={"metadata_key": "metadata_value"},
| )
|
| # model uri for the above model
| model_uri = "models:/model-with-metadata/1"
|
| # Load the model and access the custom metadata
| model = mlflow.pyfunc.load_model(model_uri=model_uri)
| assert model.metadata.metadata["metadata_key"] == "metadata_value"
|
| model_size_bytes
| An optional integer that represents the model size in bytes
|
| :getter: Retrieves the model size if it's calculated when the model is saved
| :setter: Sets the model size to a model instance
| :type: Optional[int]
|
| resources
| An optional dictionary that contains the resources required to serve the model.
|
| :getter: Retrieves the resources required to serve the model
| :setter: Sets the resources required to serve the model
| :type: Dict[str, Dict[ResourceType, List[Dict]]]
|
| saved_input_example_info
| A dictionary that contains the metadata of the saved input example, e.g.,
| ``{"artifact_path": "input_example.json", "type": "dataframe", "pandas_orient": "split"}``.
|
| signature
| An optional definition of the expected inputs to and outputs from a model object, defined
| with both field names and data types. Signatures support both column-based and tensor-based
| inputs and outputs.
|
| :getter: Retrieves the signature of a model instance iff the model was saved with a
| signature definition.
| :setter: Sets a signature to a model instance.
| :type: Optional[ModelSignature]
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __hash__ = None
class ModelConfig(builtins.object)
| ModelConfig(*, development_config: str | dict[str, typing.Any] | None = None)
|
| ModelConfig used in code to read a YAML configuration file or a dictionary.
|
| Args:
| development_config: Path to the YAML configuration file or a dictionary containing the
| configuration. If the configuration is not provided, an error is raised
|
| .. code-block:: python
| :caption: Example usage in model code
|
| from mlflow.models import ModelConfig
|
| # Load the configuration from a dictionary
| config = ModelConfig(development_config={"key1": "value1"})
| print(config.get("key1"))
|
|
| .. code-block:: yaml
| :caption: yaml file for model configuration
|
| key1: value1
| another_key:
| - value2
| - value3
|
| .. code-block:: python
| :caption: Example yaml usage in model code
|
| from mlflow.models import ModelConfig
|
| # Load the configuration from a file
| config = ModelConfig(development_config="config.yaml")
| print(config.get("key1"))
|
|
| When invoking the ModelConfig locally in a model file, development_config can be passed in
| which would be used as configuration for the model.
|
|
| .. code-block:: python
| :caption: Example to use ModelConfig when logging model as code: agent.py
|
| import mlflow
| from mlflow.models import ModelConfig
|
| config = ModelConfig(development_config={"key1": "value1"})
|
|
| class TestModel(mlflow.pyfunc.PythonModel):
| def predict(self, context, model_input, params=None):
| return config.get("key1")
|
|
| mlflow.models.set_model(TestModel())
|
|
| But this development_config configuration file will be overridden when logging a model.
| When no model_config is passed in while logging the model, an error will be raised when
| trying to load the model using ModelConfig.
| Note: development_config is not used when logging the model.
|
|
| .. code-block:: python
| :caption: Example to use agent.py to log the model: deploy.py
|
| model_config = {"key1": "value2"}
| with mlflow.start_run():
| model_info = mlflow.pyfunc.log_model(
| name="model", python_model="agent.py", model_config=model_config
| )
|
| loaded_model = mlflow.pyfunc.load_model(model_info.model_uri)
|
| # This will print "value2" as the model_config passed in while logging the model
| print(loaded_model.predict(None))
|
| Methods defined here:
|
| __init__(self, *, development_config: str | dict[str, typing.Any] | None = None)
| Initialize self. See help(type(self)) for accurate signature.
|
| get(self, key)
| Gets the value of a top-level parameter in the configuration.
|
| to_dict(self)
| Returns the configuration as a dictionary.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class ModelSignature(builtins.object)
| ModelSignature(inputs: mlflow.types.schema.Schema | typing.Any = None, outputs: mlflow.types.schema.Schema | typing.Any = None, params: mlflow.types.schema.ParamSchema = None)
|
| ModelSignature specifies schema of model's inputs, outputs and params.
|
| ModelSignature can be :py:func:`inferred <mlflow.models.infer_signature>` from training
| dataset, model predictions using and params for inference, or constructed by hand by
| passing an input and output :py:class:`Schema <mlflow.types.Schema>`, and params
| :py:class:`ParamSchema <mlflow.types.ParamSchema>`.
|
| Methods defined here:
|
| __eq__(self, other) -> bool
| Return self==value.
|
| __init__(self, inputs: mlflow.types.schema.Schema | typing.Any = None, outputs: mlflow.types.schema.Schema | typing.Any = None, params: mlflow.types.schema.ParamSchema = None)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self) -> str
| Return repr(self).
|
| to_dict(self) -> dict[str, typing.Any]
| Serialize into a 'jsonable' dictionary.
|
| Input and output schema are represented as json strings. This is so that the
| representation is compact when embedded in an MLmodel yaml file.
|
| Returns:
| dictionary representation with input and output schema represented as json strings.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dict(signature_dict: dict[str, typing.Any])
| Deserialize from dictionary representation.
|
| Args:
| signature_dict: Dictionary representation of model signature.
| Expected dictionary format:
| `{'inputs': <json string>,
| 'outputs': <json string>,
| 'params': <json string>" }`
|
| Returns:
| ModelSignature populated with the data form the dictionary.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __hash__ = None
class Resource(abc.ABC)
| Base class for defining the resources needed to serve a model.
|
| Args:
| type (ResourceType): The resource type.
| target_uri (str): The target URI where these resources are hosted.
|
| Method resolution order:
| Resource
| abc.ABC
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other: Any)
| Return self==value.
|
| to_dict(self)
| Convert the resource to a dictionary.
| Subclasses must implement this method.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dict(data: dict[str, str])
| Convert the dictionary to a Resource.
| Subclasses must implement this method.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| target_uri
| The target URI where the resource is hosted (must be defined by subclasses).
|
| type
| The resource type (must be defined by subclasses).
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset({'from_dict', 'target_uri', 'to_dict',...
|
| __annotations__ = {}
|
| __hash__ = None
class ResourceType(enum.Enum)
| ResourceType(*values)
|
| Enum to define the different types of resources needed to serve a model.
|
| Method resolution order:
| ResourceType
| enum.Enum
| builtins.object
|
| Data and other attributes defined here:
|
| APP = <ResourceType.APP: 'app'>
|
| FUNCTION = <ResourceType.FUNCTION: 'function'>
|
| GENIE_SPACE = <ResourceType.GENIE_SPACE: 'genie_space'>
|
| LAKEBASE = <ResourceType.LAKEBASE: 'lakebase'>
|
| SERVING_ENDPOINT = <ResourceType.SERVING_ENDPOINT: 'serving_endpoint'>
|
| SQL_WAREHOUSE = <ResourceType.SQL_WAREHOUSE: 'sql_warehouse'>
|
| TABLE = <ResourceType.TABLE: 'table'>
|
| UC_CONNECTION = <ResourceType.UC_CONNECTION: 'uc_connection'>
|
| VECTOR_SEARCH_INDEX = <ResourceType.VECTOR_SEARCH_INDEX: 'vector_searc...
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Static methods inherited from enum.EnumType:
|
| __contains__(value)
| Return True if `value` is in `cls`.
|
| `value` is in `cls` if:
| 1) `value` is a member of `cls`, or
| 2) `value` is the value of one of the `cls`'s members.
|
| __getitem__(name)
| Return the member matching `name`.
|
| __iter__()
| Return members in definition order.
|
| __len__()
| Return the number of members (no aliases)
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
FUNCTIONS
add_libraries_to_model(model_uri, run_id=None, registered_model_name=None)
Given a registered model_uri (e.g. models:/<model_name>/<model_version>), this utility
re-logs the model along with all the required model libraries back to the Model Registry.
The required model libraries are stored along with the model as model artifacts. In
addition, supporting files to the model (e.g. conda.yaml, requirements.txt) are modified
to use the added libraries.
By default, this utility creates a new model version under the same registered model specified
by ``model_uri``. This behavior can be overridden by specifying the ``registered_model_name``
argument.
Args:
model_uri: A registered model uri in the Model Registry of the form
models:/<model_name>/<model_version/stage/latest>
run_id: The ID of the run to which the model with libraries is logged. If None, the model
with libraries is logged to the source run corresponding to model version
specified by ``model_uri``; if the model version does not have a source run, a
new run created.
registered_model_name: The new model version (model with its libraries) is
registered under the inputted registered_model_name. If None, a
new version is logged to the existing model in the Model Registry.
.. note::
This utility only operates on a model that has been registered to the Model Registry.
.. note::
The libraries are only compatible with the platform on which they are added. Cross platform
libraries are not supported.
.. code-block:: python
:caption: Example
# Create and log a model to the Model Registry
import pandas as pd
from sklearn import datasets
from sklearn.ensemble import RandomForestClassifier
import mlflow
import mlflow.sklearn
from mlflow.models import infer_signature
with mlflow.start_run():
iris = datasets.load_iris()
iris_train = pd.DataFrame(iris.data, columns=iris.feature_names)
clf = RandomForestClassifier(max_depth=7, random_state=0)
clf.fit(iris_train, iris.target)
signature = infer_signature(iris_train, clf.predict(iris_train))
mlflow.sklearn.log_model(
clf,
name="iris_rf",
signature=signature,
registered_model_name="model-with-libs",
)
# model uri for the above model
model_uri = "models:/model-with-libs/1"
# Import utility
from mlflow.models.utils import add_libraries_to_model
# Log libraries to the original run of the model
add_libraries_to_model(model_uri)
# Log libraries to some run_id
existing_run_id = "21df94e6bdef4631a9d9cb56f211767f"
add_libraries_to_model(model_uri, run_id=existing_run_id)
# Log libraries to a new run
with mlflow.start_run():
add_libraries_to_model(model_uri)
# Log libraries to a new registered model named 'new-model'
with mlflow.start_run():
add_libraries_to_model(model_uri, registered_model_name="new-model")
build_docker(model_uri=None, name='mlflow-pyfunc', env_manager='virtualenv', mlflow_home=None, install_java=False, install_mlflow=False, base_image=None)
Builds a Docker image whose default entrypoint serves an MLflow model at port 8080, using the
python_function flavor. The container serves the model referenced by ``model_uri``, if
specified. If ``model_uri`` is not specified, an MLflow Model directory must be mounted as a
volume into the /opt/ml/model directory in the container.
.. important::
Since MLflow 2.10.1, the Docker image built with ``--model-uri`` does **not install Java**
for improved performance, unless the model flavor is one of ``["johnsnowlabs", "h2o"
"spark"]``. If you need to install Java for other flavors, e.g. custom Python model
that uses SparkML, please specify ``install-java=True`` to enforce Java installation.
For earlier versions, Java is always installed to the image.
.. warning::
If ``model_uri`` is unspecified, the resulting image doesn't support serving models with
the RFunc server.
NB: by default, the container will start nginx and uvicorn processes. If you don't need the
nginx process to be started (for instance if you deploy your container to Google Cloud Run),
you can disable it via the DISABLE_NGINX environment variable:
.. code:: bash
docker run -p 5001:8080 -e DISABLE_NGINX=true "my-image-name"
See https://www.mlflow.org/docs/latest/python_api/mlflow.pyfunc.html for more information on the
'python_function' flavor.
Args:
model_uri: URI to the model. A local path, a 'runs:/' URI, or a remote storage URI (e.g.,
an 's3://' URI). For more information about supported remote URIs for model artifacts,
see https://mlflow.org/docs/latest/tracking.html#artifact-stores
name: Name of the Docker image to build. Defaults to 'mlflow-pyfunc'.
env_manager: If specified, create an environment for MLmodel using the specified environment
manager. The following values are supported: (1) virtualenv (default): use virtualenv
and pyenv for Python version management (2) conda: use conda (3) local: use the local
environment without creating a new one.
mlflow_home: Path to local clone of MLflow project. Use for development only.
install_java: If specified, install Java in the image. Default is False in order to
reduce both the image size and the build time. Model flavors requiring Java will enable
this setting automatically, such as the Spark flavor. (This argument is only available
in MLflow 2.10.1 and later. In earlier versions, Java is always installed to the image.)
install_mlflow: If specified and there is a conda or virtualenv environment to be activated
mlflow will be installed into the environment after it has been activated.
The version of installed mlflow will be the same as the one used to invoke this command.
base_image: Base image for the Docker image. If not specified, the default image is either
UBUNTU_BASE_IMAGE = "ubuntu:22.04" or PYTHON_SLIM_BASE_IMAGE = "python:{version}-slim"
Note: If custom image is used, there are no guarantees that the image will work. You
may find greater compatibility by building your image on top of the ubuntu images. In
addition, you must install Java and virtualenv to have the image work properly.
convert_input_example_to_serving_input(input_example) -> str | None
Helper function to convert a model's input example to a serving input example that
can be used for model inference in the scoring server.
Args:
input_example: model input example. Supported types are pandas.DataFrame, numpy.ndarray,
dictionary of (name -> numpy.ndarray), list, scalars and dicts with json serializable
values.
Returns:
serving input example as a json string
evaluate(model=None, data=None, *, model_type=None, targets=None, predictions=None, dataset_path=None, feature_names=None, evaluators=None, evaluator_config=None, extra_metrics=None, custom_artifacts=None, env_manager='local', model_config=None, inference_params=None, model_id=None, _called_from_genai_evaluate=False)
Evaluate the model performance on given data and selected metrics.
This function evaluates a PyFunc model or custom callable on the specified dataset using
specified ``evaluators``, and logs resulting metrics & artifacts to MLflow tracking server.
Users can also skip setting ``model`` and put the model outputs in ``data`` directly for
evaluation. For detailed information, please read
`the Model Evaluation documentation <../../model-evaluation/index.html>`_.
Default Evaluator behavior:
- The default evaluator, which can be invoked with ``evaluators="default"`` or
``evaluators=None``, supports model types listed below. For each pre-defined model type, the
default evaluator evaluates your model on a selected set of metrics and generate artifacts
like plots. Please find more details below.
- For both the ``"regressor"`` and ``"classifier"`` model types, the default evaluator
generates model summary plots and feature importance plots using
`SHAP <https://shap.readthedocs.io/en/latest/index.html>`_.
- For regressor models, the default evaluator additionally logs:
- **metrics**: example_count, mean_absolute_error, mean_squared_error,
root_mean_squared_error, sum_on_target, mean_on_target, r2_score, max_error,
mean_absolute_percentage_error.
- For binary classifiers, the default evaluator additionally logs:
- **metrics**: true_negatives, false_positives, false_negatives, true_positives, recall,
precision, f1_score, accuracy_score, example_count, log_loss, roc_auc,
precision_recall_auc.
- **artifacts**: lift curve plot, precision-recall plot, ROC plot.
- For multiclass classifiers, the default evaluator additionally logs:
- **metrics**: accuracy_score, example_count, f1_score_micro, f1_score_macro, log_loss
- **artifacts**: A CSV file for "per_class_metrics" (per-class metrics includes
true_negatives/false_positives/false_negatives/true_positives/recall/precision/roc_auc,
precision_recall_auc), precision-recall merged curves plot, ROC merged curves plot.
- For question-answering models, the default evaluator logs:
- **metrics**: ``exact_match``, ``token_count``, `toxicity`_ (requires `evaluate`_,
`torch`_, `flesch_kincaid_grade_level`_ (requires `textstat`_) and `ari_grade_level`_.
- **artifacts**: A JSON file containing the inputs, outputs, targets (if the ``targets``
argument is supplied), and per-row metrics of the model in tabular format.
.. _toxicity:
https://huggingface.co/spaces/evaluate-measurement/toxicity
.. _torch:
https://pytorch.org/get-started/locally/
.. _transformers:
https://huggingface.co/docs/transformers/installation
.. _ari_grade_level:
https://en.wikipedia.org/wiki/Automated_readability_index
.. _flesch_kincaid_grade_level:
https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests#Flesch%E2%80%93Kincaid_grade_level
.. _evaluate:
https://pypi.org/project/evaluate
.. _textstat:
https://pypi.org/project/textstat
- For text-summarization models, the default evaluator logs:
- **metrics**: ``token_count``, `ROUGE`_ (requires `evaluate`_, `nltk`_, and
`rouge_score`_ to be installed), `toxicity`_ (requires `evaluate`_, `torch`_,
`transformers`_), `ari_grade_level`_ (requires `textstat`_),
`flesch_kincaid_grade_level`_ (requires `textstat`_).
- **artifacts**: A JSON file containing the inputs, outputs, targets (if the ``targets``
argument is supplied), and per-row metrics of the model in the tabular format.
.. _ROUGE:
https://huggingface.co/spaces/evaluate-metric/rouge
.. _toxicity:
https://huggingface.co/spaces/evaluate-measurement/toxicity
.. _torch:
https://pytorch.org/get-started/locally/
.. _transformers:
https://huggingface.co/docs/transformers/installation
.. _ari_grade_level:
https://en.wikipedia.org/wiki/Automated_readability_index
.. _flesch_kincaid_grade_level:
https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests#Flesch%E2%80%93Kincaid_grade_level
.. _evaluate:
https://pypi.org/project/evaluate
.. _nltk:
https://pypi.org/project/nltk
.. _rouge_score:
https://pypi.org/project/rouge-score
.. _textstat:
https://pypi.org/project/textstat
- For text models, the default evaluator logs:
- **metrics**: ``token_count``, `toxicity`_ (requires `evaluate`_, `torch`_,
`transformers`_), `ari_grade_level`_ (requires `textstat`_),
`flesch_kincaid_grade_level`_ (requires `textstat`_).
- **artifacts**: A JSON file containing the inputs, outputs, targets (if the ``targets``
argument is supplied), and per-row metrics of the model in tabular format.
.. _evaluate:
https://pypi.org/project/evaluate
.. _toxicity:
https://huggingface.co/spaces/evaluate-measurement/toxicity
.. _torch:
https://pytorch.org/get-started/locally/
.. _transformers:
https://huggingface.co/docs/transformers/installation
.. _ari_grade_level:
https://en.wikipedia.org/wiki/Automated_readability_index
.. _flesch_kincaid_grade_level:
https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests#Flesch%E2%80%93Kincaid_grade_level
.. _textstat:
https://pypi.org/project/textstat
- For retriever models, the default evaluator logs:
- **metrics**: :mod:`precision_at_k(k) <mlflow.metrics.precision_at_k>`,
:mod:`recall_at_k(k) <mlflow.metrics.recall_at_k>` and
:mod:`ndcg_at_k(k) <mlflow.metrics.ndcg_at_k>` - all have a default value of
``retriever_k`` = 3.
- **artifacts**: A JSON file containing the inputs, outputs, targets, and per-row metrics
of the model in tabular format.
- For sklearn models, the default evaluator additionally logs the model's evaluation criterion
(e.g. mean accuracy for a classifier) computed by `model.score` method.
- The metrics/artifacts listed above are logged to the active MLflow run.
If no active run exists, a new MLflow run is created for logging these metrics and
artifacts.
- Additionally, information about the specified dataset - hash, name (if specified), path
(if specified), and the UUID of the model that evaluated it - is logged to the
``mlflow.datasets`` tag.
- The available ``evaluator_config`` options for the default evaluator include:
- **log_model_explainability**: A boolean value specifying whether or not to log model
explainability insights, default value is True.
- **log_explainer**: If True, log the explainer used to compute model explainability
insights as a model. Default value is False.
- **explainability_algorithm**: A string to specify the SHAP Explainer algorithm for model
explainability. Supported algorithm includes: 'exact', 'permutation', 'partition',
'kernel'.
If not set, ``shap.Explainer`` is used with the "auto" algorithm, which chooses the best
Explainer based on the model.
- **explainability_nsamples**: The number of sample rows to use for computing model
explainability insights. Default value is 2000.
- **explainability_kernel_link**: The kernel link function used by shap kernel explainer.
Available values are "identity" and "logit". Default value is "identity".
- **max_classes_for_multiclass_roc_pr**:
For multiclass classification tasks, the maximum number of classes for which to log
the per-class ROC curve and Precision-Recall curve. If the number of classes is
larger than the configured maximum, these curves are not logged.
- **metric_prefix**: An optional prefix to prepend to the name of each metric and artifact
produced during evaluation.
- **log_metrics_with_dataset_info**: A boolean value specifying whether or not to include
information about the evaluation dataset in the name of each metric logged to MLflow
Tracking during evaluation, default value is True.
- **pos_label**: If specified, the positive label to use when computing classification
metrics such as precision, recall, f1, etc. for binary classification models. For
multiclass classification and regression models, this parameter will be ignored.
- **average**: The averaging method to use when computing classification metrics such as
precision, recall, f1, etc. for multiclass classification models
(default: ``'weighted'``). For binary classification and regression models, this
parameter will be ignored.
- **sample_weights**: Weights for each sample to apply when computing model performance
metrics.
- **col_mapping**: A dictionary mapping column names in the input dataset or output
predictions to column names used when invoking the evaluation functions.
- **retriever_k**: A parameter used when ``model_type="retriever"`` as the number of
top-ranked retrieved documents to use when computing the built-in metric
:mod:`precision_at_k(k) <mlflow.metrics.precision_at_k>`,
:mod:`recall_at_k(k) <mlflow.metrics.recall_at_k>` and
:mod:`ndcg_at_k(k) <mlflow.metrics.ndcg_at_k>`. Default value is 3. For all other
model types, this parameter will be ignored.
- Limitations of evaluation dataset:
- For classification tasks, dataset labels are used to infer the total number of classes.
- For binary classification tasks, the negative label value must be 0 or -1 or False, and
the positive label value must be 1 or True.
- Limitations of metrics/artifacts computation:
- For classification tasks, some metric and artifact computations require the model to
output class probabilities. Currently, for scikit-learn models, the default evaluator
calls the ``predict_proba`` method on the underlying model to obtain probabilities. For
other model types, the default evaluator does not compute metrics/artifacts that require
probability outputs.
- Limitations of default evaluator logging model explainability insights:
- The ``shap.Explainer`` ``auto`` algorithm uses the ``Linear`` explainer for linear models
and the ``Tree`` explainer for tree models. Because SHAP's ``Linear`` and ``Tree``
explainers do not support multi-class classification, the default evaluator falls back to
using the ``Exact`` or ``Permutation`` explainers for multi-class classification tasks.
- Logging model explainability insights is not currently supported for PySpark models.
- The evaluation dataset label values must be numeric or boolean, all feature values
must be numeric, and each feature column must only contain scalar values.
- Limitations when environment restoration is enabled:
- When environment restoration is enabled for the evaluated model (i.e. a non-local
``env_manager`` is specified), the model is loaded as a client that invokes a MLflow
Model Scoring Server process in an independent Python environment with the model's
training time dependencies installed. As such, methods like ``predict_proba`` (for
probability outputs) or ``score`` (computes the evaluation criterian for sklearn models)
of the model become inaccessible and the default evaluator does not compute metrics or
artifacts that require those methods.
- Because the model is an MLflow Model Server process, SHAP explanations are slower to
compute. As such, model explainaibility is disabled when a non-local ``env_manager``
specified, unless the ``evaluator_config`` option **log_model_explainability** is
explicitly set to ``True``.
Args:
model: Optional. If specified, it should be one of the following:
- A pyfunc model instance
- A URI referring to a pyfunc model
- A URI referring to an MLflow Deployments endpoint e.g. ``"endpoints:/my-chat"``
- A callable function: This function should be able to take in model input and
return predictions. It should follow the signature of the
:py:func:`predict <mlflow.pyfunc.PyFuncModel.predict>` method. Here's an example
of a valid function:
.. code-block:: python
model = mlflow.pyfunc.load_model(model_uri)
def fn(model_input):
return model.predict(model_input)
If omitted, it indicates a static dataset will be used for evaluation instead of a
model. In this case, the ``data`` argument must be a Pandas DataFrame or an mlflow
PandasDataset that contains model outputs, and the ``predictions`` argument must be the
name of the column in ``data`` that contains model outputs.
data: One of the
following:
- A numpy array or list of evaluation features, excluding labels.
- A Pandas DataFrame containing evaluation features, labels, and optionally model
outputs. Model outputs are required to be provided when model is unspecified.
If ``feature_names`` argument not specified, all columns except for the label
column and predictions column are regarded as feature columns. Otherwise,
only column names present in ``feature_names`` are regarded as feature columns.
- A Spark DataFrame containing evaluation features and labels. If
``feature_names`` argument not specified, all columns except for the label
column are regarded as feature columns. Otherwise, only column names present in
``feature_names`` are regarded as feature columns. Only the first 10000 rows in
the Spark DataFrame will be used as evaluation data.
- A :py:class:`mlflow.data.dataset.Dataset` instance containing evaluation
features, labels, and optionally model outputs. Model outputs are only supported
with a PandasDataset. Model outputs are required when model is unspecified, and
should be specified via the ``predictions`` property of the PandasDataset.
model_type: (Optional) A string describing the model type. The default evaluator
supports the following model types:
- ``'classifier'``
- ``'regressor'``
- ``'question-answering'``
- ``'text-summarization'``
- ``'text'``
- ``'retriever'``
If no ``model_type`` is specified, then you must provide a list of
metrics to compute via the ``extra_metrics`` param.
.. note::
``'question-answering'``, ``'text-summarization'``, ``'text'``, and
``'retriever'`` are experimental and may be changed or removed in a
future release.
targets: If ``data`` is a numpy array or list, a numpy array or list of evaluation
labels. If ``data`` is a DataFrame, the string name of a column from ``data``
that contains evaluation labels. Required for classifier and regressor models,
but optional for question-answering, text-summarization, and text models. If
``data`` is a :py:class:`mlflow.data.dataset.Dataset` that defines targets,
then ``targets`` is optional.
predictions: Optional. The name of the column that contains model outputs.
- When ``model`` is specified and outputs multiple columns, ``predictions`` can be used
to specify the name of the column that will be used to store model outputs for
evaluation.
- When ``model`` is not specified and ``data`` is a pandas dataframe,
``predictions`` can be used to specify the name of the column in ``data`` that
contains model outputs.
.. code-block:: python
:caption: Example usage of predictions
# Evaluate a model that outputs multiple columns
data = pd.DataFrame({"question": ["foo"]})
def model(inputs):
return pd.DataFrame({"answer": ["bar"], "source": ["baz"]})
results = evaluate(
model=model,
data=data,
predictions="answer",
# other arguments if needed
)
# Evaluate a static dataset
data = pd.DataFrame({"question": ["foo"], "answer": ["bar"], "source": ["baz"]})
results = evaluate(
data=data,
predictions="answer",
# other arguments if needed
)
dataset_path: (Optional) The path where the data is stored. Must not contain double
quotes (``"``). If specified, the path is logged to the ``mlflow.datasets``
tag for lineage tracking purposes.
feature_names: (Optional) A list. If the ``data`` argument is a numpy array or list,
``feature_names`` is a list of the feature names for each feature. If
``feature_names=None``, then the ``feature_names`` are generated using the
format ``feature_{feature_index}``. If the ``data`` argument is a Pandas
DataFrame or a Spark DataFrame, ``feature_names`` is a list of the names
of the feature columns in the DataFrame. If ``feature_names=None``, then
all columns except the label column and the predictions column are
regarded as feature columns.
evaluators: The name of the evaluator to use for model evaluation, or a list of
evaluator names. If unspecified, all evaluators capable of evaluating the
specified model on the specified dataset are used. The default evaluator
can be referred to by the name ``"default"``. To see all available
evaluators, call :py:func:`mlflow.models.list_evaluators`.
evaluator_config: A dictionary of additional configurations to supply to the evaluator.
If multiple evaluators are specified, each configuration should be
supplied as a nested dictionary whose key is the evaluator name.
extra_metrics:
(Optional) A list of :py:class:`EvaluationMetric <mlflow.models.EvaluationMetric>`
objects. These metrics are computed in addition to the default metrics associated with
pre-defined `model_type`, and setting `model_type=None` will only compute the metrics
specified in `extra_metrics`. See the `mlflow.metrics` module for more information about
the builtin metrics and how to define extra metrics.
.. code-block:: python
:caption: Example usage of extra metrics
import mlflow
import numpy as np
def root_mean_squared_error(eval_df, _builtin_metrics):
return np.sqrt((np.abs(eval_df["prediction"] - eval_df["target"]) ** 2).mean())
rmse_metric = mlflow.models.make_metric(
eval_fn=root_mean_squared_error,
greater_is_better=False,
)
mlflow.evaluate(..., extra_metrics=[rmse_metric])
custom_artifacts:
(Optional) A list of custom artifact functions with the following signature:
.. code-block:: python
def custom_artifact(
eval_df: Union[pandas.Dataframe, pyspark.sql.DataFrame],
builtin_metrics: Dict[str, float],
artifacts_dir: str,
) -> Dict[str, Any]:
"""
Args:
eval_df:
A Pandas or Spark DataFrame containing ``prediction`` and ``target``
column. The ``prediction`` column contains the predictions made by the
model. The ``target`` column contains the corresponding labels to the
predictions made on that row.
builtin_metrics:
A dictionary containing the metrics calculated by the default evaluator.
The keys are the names of the metrics and the values are the scalar
values of the metrics. Refer to the DefaultEvaluator behavior section
for what metrics will be returned based on the type of model (i.e.
classifier or regressor).
artifacts_dir:
A temporary directory path that can be used by the custom artifacts
function to temporarily store produced artifacts. The directory will be
deleted after the artifacts are logged.
Returns:
A dictionary that maps artifact names to artifact objects
(e.g. a Matplotlib Figure) or to artifact paths within ``artifacts_dir``.
"""
...
Object types that artifacts can be represented as:
- A string uri representing the file path to the artifact. MLflow will infer the
type of the artifact based on the file extension.
- A string representation of a JSON object. This will be saved as a .json artifact.
- Pandas DataFrame. This will be resolved as a CSV artifact.
- Numpy array. This will be saved as a .npy artifact.
- Matplotlib Figure. This will be saved as an image artifact. Note that
``matplotlib.pyplot.savefig`` is called behind the scene with default
configurations.
To customize, either save the figure with the desired configurations and return
its file path or define customizations through environment variables in
``matplotlib.rcParams``.
- Other objects will be attempted to be pickled with the default protocol.
.. code-block:: python
:caption: Example usage of custom artifacts
import mlflow
import matplotlib.pyplot as plt
def scatter_plot(eval_df, builtin_metrics, artifacts_dir):
plt.scatter(eval_df["prediction"], eval_df["target"])
plt.xlabel("Targets")
plt.ylabel("Predictions")
plt.title("Targets vs. Predictions")
plt.savefig(os.path.join(artifacts_dir, "example.png"))
plt.close()
return {"pred_target_scatter": os.path.join(artifacts_dir, "example.png")}
def pred_sample(eval_df, _builtin_metrics, _artifacts_dir):
return {"pred_sample": pred_sample.head(10)}
mlflow.evaluate(..., custom_artifacts=[scatter_plot, pred_sample])
env_manager: Specify an environment manager to load the candidate ``model`` in
isolated Python environments and restore their
dependencies. Default value is ``local``, and the following values are
supported:
- ``virtualenv``: (Recommended) Use virtualenv to restore the python
environment that was used to train the model.
- ``conda``: Use Conda to restore the software environment that was used
to train the model.
- ``local``: Use the current Python environment for model inference, which
may differ from the environment used to train the model and may lead to
errors or invalid predictions.
model_config: the model configuration to use for loading the model with pyfunc. Inspect
the model's pyfunc flavor to know which keys are supported for your
specific model. If not indicated, the default model configuration
from the model is used (if any).
inference_params: (Optional) A dictionary of inference parameters to be passed to the model
when making predictions, such as ``{"max_tokens": 100}``. This is only used when
the ``model`` is an MLflow Deployments endpoint URI e.g. ``"endpoints:/my-chat"``
model_id: (Optional) The ID of the MLflow LoggedModel or Model Version to which the
evaluation results (e.g. metrics and traces) will be linked. If `model_id` is not
specified but `model` is specified, the ID from `model` will be used.
_called_from_genai_evaluate: (Optional) Only used internally.
Returns:
An :py:class:`mlflow.models.EvaluationResult` instance containing
metrics of evaluating the model with the given dataset.
get_model_info(model_uri: str) -> mlflow.models.model.ModelInfo
Get metadata for the specified model, such as its input/output signature.
Args:
model_uri: The location, in URI format, of the MLflow model. For example:
- ``/Users/me/path/to/local/model``
- ``relative/path/to/local/model``
- ``s3://my_bucket/path/to/model``
- ``runs:/<mlflow_run_id>/run-relative/path/to/model``
- ``models:/<model_name>/<model_version>``
- ``models:/<model_name>/<stage>``
- ``mlflow-artifacts:/path/to/model``
For more information about supported URI schemes, see
`Referencing Artifacts <https://www.mlflow.org/docs/latest/concepts.html#
artifact-locations>`_.
Returns:
A :py:class:`ModelInfo <mlflow.models.model.ModelInfo>` instance that contains the
metadata of the logged model.
.. code-block:: python
:caption: Example usage of get_model_info
import mlflow.models
import mlflow.sklearn
from sklearn.ensemble import RandomForestRegressor
with mlflow.start_run() as run:
params = {"n_estimators": 3, "random_state": 42}
X = [[0, 1]]
y = [1]
signature = mlflow.models.infer_signature(X, y)
rfr = RandomForestRegressor(**params).fit(X, y)
mlflow.log_params(params)
mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
model_uri = f"runs:/{run.info.run_id}/sklearn-model"
# Get model info with model_uri
model_info = mlflow.models.get_model_info(model_uri)
# Get model signature directly
model_signature = model_info.signature
assert model_signature == signature
infer_pip_requirements(model_uri, flavor, fallback=None, timeout=None, extra_env_vars=None, uv_project_dir=None, uv_groups=None, uv_extras=None)
Infers the pip requirements of the specified model by creating a subprocess and loading
the model in it to determine which packages are imported.
If a uv project is detected (contains both uv.lock and pyproject.toml), this function
will first attempt to export dependencies via ``uv export``. If that succeeds, those
requirements are returned. Otherwise, falls back to inferring dependencies by capturing
imported packages during model inference.
Args:
model_uri: The URI of the model.
flavor: The flavor name of the model.
fallback: If provided, an unexpected error during the inference procedure is swallowed
and the value of ``fallback`` is returned. Otherwise, the error is raised.
timeout: If specified, the inference operation is bound by the timeout (in seconds).
extra_env_vars: A dictionary of extra environment variables to pass to the subprocess.
Default to None.
uv_project_dir: Explicit path to a uv project directory. When provided, overrides
the ``MLFLOW_UV_AUTO_DETECT`` environment variable and searches the specified
directory instead of cwd. Default to None (auto-detect from cwd).
uv_groups: Optional list of uv dependency groups to include when exporting
requirements. Maps to ``uv export --group <name>``.
uv_extras: Optional list of uv extras (optional dependency sets) to include
when exporting requirements. Maps to ``uv export --extra <name>``.
Returns:
A list of inferred pip requirements (e.g. ``["scikit-learn==0.24.2", ...]``).
infer_signature(model_input: Any = None, model_output: 'MlflowInferableDataset' = None, params: dict[str, typing.Any] | None = None) -> mlflow.models.signature.ModelSignature
Infer an MLflow model signature from the training data (input), model predictions (output)
and parameters (for inference).
The signature represents model input and output as data frames with (optionally) named columns
and data type specified as one of types defined in :py:class:`mlflow.types.DataType`. It also
includes parameters schema for inference, .
This method will raise an exception if the user data contains incompatible types or is not
passed in one of the supported formats listed below.
The input should be one of these:
- pandas.DataFrame
- pandas.Series
- dictionary of { name -> numpy.ndarray}
- numpy.ndarray
- pyspark.sql.DataFrame
- scipy.sparse.csr_matrix
- scipy.sparse.csc_matrix
- dictionary / list of dictionaries of JSON-convertible types
The element types should be mappable to one of :py:class:`mlflow.types.DataType`.
For pyspark.sql.DataFrame inputs, columns of type DateType and TimestampType are both inferred
as type :py:data:`datetime <mlflow.types.DataType.datetime>`, which is coerced to
TimestampType at inference.
Args:
model_input: Valid input to the model. E.g. (a subset of) the training dataset.
model_output: Valid model output. E.g. Model predictions for the (subset of) training
dataset.
params: Valid parameters for inference. It should be a dictionary of parameters
that can be set on the model during inference by passing `params` to pyfunc
`predict` method.
An example of valid parameters:
.. code-block:: python
# Define parameters for inference
params = {
"num_beams": 5,
"max_length": 30,
"do_sample": True,
"remove_invalid_values": True,
}
import mlflow
# For transformers models, pass input_example directly to
# log_model/save_model to automatically infer the signature:
mlflow.transformers.save_model(
model,
path=model_path,
input_example=(data, params),
)
pyfunc_loaded = mlflow.pyfunc.load_model(model_path)
# Passing params to `predict` function directly
result = pyfunc_loaded.predict(data, params=params)
Returns:
ModelSignature
list_evaluators()
Return a name list for all available Evaluators.
make_metric(*, eval_fn, greater_is_better, name=None, long_name=None, version=None, metric_details=None, metric_metadata=None, genai_metric_args=None)
A factory function to create an :py:class:`EvaluationMetric` object.
Args:
eval_fn: A function that computes the metric with the following signature:
.. code-block:: python
def eval_fn(
predictions: pandas.Series,
targets: pandas.Series,
metrics: Dict[str, MetricValue],
**kwargs,
) -> Union[float, MetricValue]:
"""
Args:
predictions: A pandas Series containing the predictions made by the model.
targets: (Optional) A pandas Series containing the corresponding labels
for the predictions made on that input.
metrics: (Optional) A dictionary containing the metrics calculated by the
default evaluator. The keys are the names of the metrics and the values
are the metric values. To access the MetricValue for the metrics
calculated by the system, make sure to specify the type hint for this
parameter as Dict[str, MetricValue]. Refer to the DefaultEvaluator
behavior section for what metrics will be returned based on the type of
model (i.e. classifier or regressor). kwargs: Includes a list of args
that are used to compute the metric. These args could information coming
from input data, model outputs or parameters specified in the
`evaluator_config` argument of the `mlflow.evaluate` API.
kwargs: Includes a list of args that are used to compute the metric. These
args could be information coming from input data, model outputs,
other metrics, or parameters specified in the `evaluator_config`
argument of the `mlflow.evaluate` API.
Returns: MetricValue with per-row scores, per-row justifications, and aggregate
results.
"""
...
greater_is_better: Whether a greater value of the metric is better.
name: The name of the metric. This argument must be specified if ``eval_fn`` is a lambda
function or the ``eval_fn.__name__`` attribute is not available.
long_name: (Optional) The long name of the metric. For example, ``"mean_squared_error"``
for ``"mse"``.
version: (Optional) The metric version. For example ``v1``.
metric_details: (Optional) A description of the metric and how it is calculated.
metric_metadata: (Optional) A dictionary containing metadata for the metric.
genai_metric_args: (Optional) A dictionary containing arguments specified by users
when calling make_genai_metric or make_genai_metric_from_prompt. Those args
are persisted so that we can deserialize the same metric object later.
.. seealso::
- :py:class:`mlflow.models.EvaluationMetric`
- :py:func:`mlflow.evaluate`
predict(model_uri, input_data=None, input_path=None, content_type='json', output_path=None, env_manager='virtualenv', install_mlflow=False, pip_requirements_override=None, extra_envs=None)
Generate predictions in json format using a saved MLflow model. For information about the input
data formats accepted by this function, see the following documentation:
https://www.mlflow.org/docs/latest/models.html#built-in-deployment-tools.
.. note::
To increase verbosity for debugging purposes (in order to inspect the full dependency
resolver operations when processing transient dependencies), consider setting the following
environment variables:
.. code-block:: bash
# For virtualenv
export PIP_VERBOSE=1
# For uv
export RUST_LOG=uv=debug
See also:
- https://pip.pypa.io/en/stable/topics/configuration/#environment-variables
- https://docs.astral.sh/uv/configuration/environment
Args:
model_uri: URI to the model. A local path, a local or remote URI e.g. runs:/, s3://.
input_data: Input data for prediction. Must be valid input for the PyFunc model. Refer
to the :py:func:`mlflow.pyfunc.PyFuncModel.predict()` for the supported input types.
.. note::
If this API fails due to errors in input_data, use
`mlflow.models.convert_input_example_to_serving_input` to manually validate
your input data.
input_path: Path to a file containing input data. If provided, 'input_data' must be None.
content_type: Content type of the input data. Can be one of {'json', 'csv'}.
output_path: File to output results to as json. If not provided, output to stdout.
env_manager: Specify a way to create an environment for MLmodel inference:
- "virtualenv" (default): use virtualenv (and pyenv for Python version management)
- "uv": use uv
- "local": use the local environment
- "conda": use conda
install_mlflow: If specified and there is a conda or virtualenv environment to be activated
mlflow will be installed into the environment after it has been activated. The version
of installed mlflow will be the same as the one used to invoke this command.
pip_requirements_override: If specified, install the specified python dependencies to the
model inference environment. This is particularly useful when you want to add extra
dependencies or try different versions of the dependencies defined in the logged model.
.. tip::
After validating the pip requirements override works as expected, you can update
the logged model's dependency using `mlflow.models.update_model_requirements` API
without re-logging it. Note that a registered model is immutable, so you need to
register a new model version with the updated model.
extra_envs: If specified, a dictionary of extra environment variables will be passed to the
model inference environment. This is useful for testing what environment variables are
needed for the model to run correctly. By default, environment variables existing in the
current os.environ are passed, and this parameter can be used to override them.
.. note::
If your model dependencies include pre-release versions such as `mlflow==3.2.0rc0`
and you are using `uv` as the environment manager, set `UV_PRERELEASE` environment
variable to "allow" in `extra_envs` to allow installing pre-release versions.
e.g. `extra_envs={"UV_PRERELEASE": "allow"}`.
.. note::
This parameter is only supported when `env_manager` is set to "virtualenv",
"conda" or "uv".
Code example:
.. code-block:: python
import mlflow
run_id = "..."
mlflow.models.predict(
model_uri=f"runs:/{run_id}/model",
input_data={"x": 1, "y": 2},
content_type="json",
)
# Run prediction with "uv" as the environment manager
mlflow.models.predict(
model_uri=f"runs:/{run_id}/model",
input_data={"x": 1, "y": 2},
env_manager="uv",
)
# Run prediction with additional pip dependencies and extra environment variables
mlflow.models.predict(
model_uri=f"runs:/{run_id}/model",
input_data={"x": 1, "y": 2},
content_type="json",
pip_requirements_override=["scikit-learn==0.23.2"],
extra_envs={"OPENAI_API_KEY": "some_value"},
)
# Run prediction with output_path
mlflow.models.predict(
model_uri=f"runs:/{run_id}/model",
input_data={"x": 1, "y": 2},
env_manager="uv",
output_path="output.json",
)
# Run prediction with pre-release versions
mlflow.models.predict(
model_uri=f"runs:/{run_id}/model",
input_data={"x": 1, "y": 2},
env_manager="uv",
extra_envs={"UV_PRERELEASE": "allow"},
)
set_model(model) -> None
When logging model as code, this function can be used to set the model object
to be logged.
Args:
model: The model object to be logged. Supported model types are:
- A Python function or callable object.
- A Langchain model or path to a Langchain model.
- A Llama Index model or path to a Llama Index model.
set_retriever_schema(*, primary_key: str, text_column: str, doc_uri: str | None = None, other_columns: list[str] | None = None, name: str | None = 'retriever')
Specify the return schema of a retriever span within your agent or generative AI app code.
.. deprecated:: 3.3.2
This function is deprecated and will be removed in a future version.
**Note**: MLflow recommends that your retriever return the default MLflow retriever output
schema described in https://mlflow.org/docs/latest/genai/data-model/traces/#retriever-spans,
in which case you do not need to call `set_retriever_schema`. APIs that read MLflow traces
and look for retriever spans, such as MLflow evaluation, will automatically detect retriever
spans that match MLflow's default retriever schema.
If your retriever does not return the default MLflow retriever output schema, call this API to
specify which fields in each retrieved document correspond to the page content, document
URI, document ID, etc. This enables downstream features like MLflow evaluation to properly
identify these fields. Note that `set_retriever_schema` assumes that your retriever span
returns a list of objects.
Args:
primary_key: The primary key of the retriever or vector index.
text_column: The name of the text column to use for the embeddings.
doc_uri: The name of the column that contains the document URI.
other_columns: A list of other columns that are part of the vector index
that need to be retrieved during trace logging.
name: The name of the retriever tool or vector store index.
.. code-block:: Python
:caption: Example
from mlflow.models import set_retriever_schema
# The following call sets the schema for a custom retriever that retrieves content from
# MLflow documentation, with an output schema like:
# [
# {
# 'document_id': '9a8292da3a9d4005a988bf0bfdd0024c',
# 'chunk_text': 'MLflow is an open-source platform, purpose-built to assist...',
# 'doc_uri': 'https://mlflow.org/docs/latest/index.html',
# 'title': 'MLflow: A Tool for Managing the Machine Learning Lifecycle'
# },
# {
# 'document_id': '7537fe93c97f4fdb9867412e9c1f9e5b',
# 'chunk_text': 'A great way to get started with MLflow is...',
# 'doc_uri': 'https://mlflow.org/docs/latest/getting-started/',
# 'title': 'Getting Started with MLflow'
# },
# ...
# ]
set_retriever_schema(
primary_key="chunk_id",
text_column="chunk_text",
doc_uri="doc_uri",
other_columns=["title"],
name="my_custom_retriever",
)
set_signature(model_uri: str, signature: mlflow.models.signature.ModelSignature)
Sets the model signature for specified model artifacts.
The process involves downloading the MLmodel file in the model artifacts (if it's non-local),
updating its model signature, and then overwriting the existing MLmodel file. Should the
artifact repository associated with the model artifacts disallow overwriting, this function will
fail.
Furthermore, as model registry artifacts are read-only, model artifacts located in the
model registry and represented by ``models:/`` URI schemes are not compatible with this API.
To set a signature on a model version, first load the source model artifacts. Following this,
generate a new model version using the loaded model artifacts and a corresponding signature.
For more information about setting signatures on model versions, see
`this doc section <https://mlflow.org/docs/latest/ml/model/signatures/#adding-signatures-to-registered-model-versions>`_.
Args:
model_uri: The location, in URI format, of the MLflow model. For example:
- ``/Users/me/path/to/local/model``
- ``relative/path/to/local/model``
- ``s3://my_bucket/path/to/model``
- ``runs:/<mlflow_run_id>/run-relative/path/to/model``
- ``mlflow-artifacts:/path/to/model``
- ``models:/<model_id>``
For more information about supported URI schemes, see
`Referencing Artifacts <https://www.mlflow.org/docs/latest/concepts.html#
artifact-locations>`_.
Please note that model URIs with the ``models:/<name>/<version>`` scheme are not
supported.
signature: ModelSignature to set on the model.
.. code-block:: python
:caption: Example
import mlflow
from mlflow.models import set_signature, infer_signature
# load model from run artifacts
run_id = "96771d893a5e46159d9f3b49bf9013e2"
artifact_path = "models"
model_uri = f"runs:/{run_id}/{artifact_path}"
model = mlflow.pyfunc.load_model(model_uri)
# determine model signature
test_df = ...
predictions = model.predict(test_df)
signature = infer_signature(test_df, predictions)
# set the signature for the logged model
set_signature(model_uri, signature)
update_model_requirements(model_uri: str, operation: Literal['add', 'remove'], requirement_list: list[str]) -> None
Add or remove requirements from a model's conda.yaml and requirements.txt files.
The process involves downloading these two files from the model artifacts
(if they're non-local), updating them with the specified requirements,
and then overwriting the existing files. Should the artifact repository
associated with the model artifacts disallow overwriting, this function will
fail.
Note that model registry URIs (i.e. URIs in the form ``models:/``) are not
supported, as artifacts in the model registry are intended to be read-only.
If adding requirements, the function will overwrite any existing requirements
that overlap, or else append the new requirements to the existing list.
If removing requirements, the function will ignore any version specifiers,
and remove all the specified package names. Any requirements that are not
found in the existing files will be ignored.
Args:
model_uri: The location, in URI format, of the MLflow model. For example:
- ``/Users/me/path/to/local/model``
- ``relative/path/to/local/model``
- ``s3://my_bucket/path/to/model``
- ``runs:/<mlflow_run_id>/run-relative/path/to/model``
- ``mlflow-artifacts:/path/to/model``
For more information about supported URI schemes, see
`Referencing Artifacts <https://www.mlflow.org/docs/latest/concepts.html#
artifact-locations>`_.
operation: The operation to perform. Must be one of "add" or "remove".
requirement_list: A list of requirements to add or remove from the model.
For example: ["numpy==1.20.3", "pandas>=1.3.3"]
validate_schema(data: Union[pandas.core.frame.DataFrame, pandas.core.series.Series, numpy.ndarray, ForwardRef('csc_matrix'), ForwardRef('csr_matrix'), List[Any], Dict[str, Any], datetime.datetime, bool, bytes, float, int, str], expected_schema: mlflow.types.schema.Schema) -> None
Validate that the input data has the expected schema.
Args:
data: Input data to be validated. Supported types are:
- pandas.DataFrame
- pandas.Series
- numpy.ndarray
- scipy.sparse.csc_matrix
- scipy.sparse.csr_matrix
- List[Any]
- Dict[str, Any]
- str
expected_schema: Expected Schema of the input data.
Raises:
mlflow.exceptions.MlflowException: when the input data does not match the schema.
.. code-block:: python
:caption: Example usage of validate_schema
import mlflow.models
# Suppose you've already got a model_uri
model_info = mlflow.models.get_model_info(model_uri)
# Get model signature directly
model_signature = model_info.signature
# validate schema
mlflow.models.validate_schema(input_data, model_signature.inputs)
validate_serving_input(model_uri: str, serving_input: str | dict[str, typing.Any])
.. Warning:: ``mlflow.models.utils.validate_serving_input`` is deprecated since 3.13.0. This method will be removed in a future release. Use ``mlflow.models.predict`` instead.
Helper function to validate the model can be served and provided input is valid
prior to serving the model.
.. note::
This API is deprecated. Use :py:func:`mlflow.models.predict` instead, which
validates the input example by running prediction in an isolated environment
(e.g. with ``env_manager="uv"``) that closely mirrors the serving environment.
Args:
model_uri: URI of the model to be served.
serving_input: Input data to be validated. Should be a dictionary or a JSON string.
Returns:
The prediction result from the model.
DATA
ModelInputExample = typing.Union[pandas.core.frame.DataFrame, numpy......
__all__ = ['Model', 'FlavorBackend', 'infer_pip_requirements', 'evalua...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\models\__init__.py
mlflow.onnx
Python Library Documentation: package mlflow.onnx in mlflow
NAME
mlflow.onnx
DESCRIPTION
The ``mlflow.onnx`` module provides APIs for logging and loading ONNX models in the MLflow Model
format. This module exports MLflow Models with the following flavors:
ONNX (native) format
This is the main flavor that can be loaded back as an ONNX model object.
:py:mod:`mlflow.pyfunc`
Produced for use by generic pyfunc-based deployment tools and batch inference.
PACKAGE CONTENTS
DATA
DEFAULT_AWAIT_MAX_SLEEP_SECONDS = 300
FLAVOR_NAME = 'onnx'
LOG_MODEL_PARAM_DOCS = ParamDocs({'name': 'Model name.', 'conda_env': ...
MLMODEL_FILE_NAME = 'MLmodel'
ModelInputExample = typing.Union[pandas.core.frame.DataFrame, numpy......
ONNX_EXECUTION_PROVIDERS = ['CUDAExecutionProvider', 'CPUExecutionProv...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\onnx\__init__.py
mlflow.openai
Python Library Documentation: package mlflow.openai in mlflow
NAME
mlflow.openai - The ``mlflow.openai`` module provides an API for logging and loading OpenAI models.
DESCRIPTION
Credential management for OpenAI on Databricks
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. warning::
Specifying secrets for model serving with ``MLFLOW_OPENAI_SECRET_SCOPE`` is deprecated.
Use `secrets-based environment variables <https://docs.databricks.com/en/machine-learning/model-serving/store-env-variable-model-serving.html>`_
instead.
When this flavor logs a model on Databricks, it saves a YAML file with the following contents as
``openai.yaml`` if the ``MLFLOW_OPENAI_SECRET_SCOPE`` environment variable is set.
.. code-block:: yaml
OPENAI_API_BASE: {scope}:openai_api_base
OPENAI_API_KEY: {scope}:openai_api_key
OPENAI_API_KEY_PATH: {scope}:openai_api_key_path
OPENAI_API_TYPE: {scope}:openai_api_type
OPENAI_ORGANIZATION: {scope}:openai_organization
- ``{scope}`` is the value of the ``MLFLOW_OPENAI_SECRET_SCOPE`` environment variable.
- The keys are the environment variables that the ``openai-python`` package uses to
configure the API client.
- The values are the references to the secrets that store the values of the environment
variables.
When the logged model is served on Databricks, each secret will be resolved and set as the
corresponding environment variable. See https://docs.databricks.com/security/secrets/index.html
for how to set up secrets on Databricks.
PACKAGE CONTENTS
_agent_tracer
api_request_parallel_processor
autolog
constant
genai_semconv_converter
model
utils (package)
FUNCTIONS
_load_pyfunc(path)
Loads PyFunc implementation. Called by ``pyfunc.load_model``.
Args:
path: Local filesystem path to the MLflow Model with the ``openai`` flavor.
autolog(disable=False, exclusive=False, disable_for_unsupported_versions=False, silent=False, log_traces=True, disable_openai_agent_tracer=True)
Enables (or disables) and configures autologging from OpenAI to MLflow.
Raises :py:class:`MlflowException <mlflow.exceptions.MlflowException>`
if the OpenAI version < 1.0.
Args:
disable: If ``True``, disables the OpenAI autologging integration. If ``False``,
enables the OpenAI autologging integration.
exclusive: If ``True``, autologged content is not logged to user-created fluent runs.
If ``False``, autologged content is logged to the active fluent run,
which may be user-created.
disable_for_unsupported_versions: If ``True``, disable autologging for versions of
OpenAI that have not been tested against this version of the MLflow
client or are incompatible.
silent: If ``True``, suppress all event logs and warnings from MLflow during OpenAI
autologging. If ``False``, show all events and warnings during OpenAI
autologging.
log_traces: If ``True``, traces are logged for OpenAI models. If ``False``, no traces are
collected during inference. Default to ``True``.
disable_openai_agent_tracer: If ``True``, disable the OpenAI Agent SDK tracer. If ``False``,
enable the OpenAI Agent SDK tracer. Default to ``True``.
load_model(model_uri, dst_path=None)
Load an OpenAI model from a local file or a run.
Args:
model_uri: The location, in URI format, of the MLflow model. For example:
- ``/Users/me/path/to/local/model``
- ``relative/path/to/local/model``
- ``s3://my_bucket/path/to/model``
- ``runs:/<mlflow_run_id>/run-relative/path/to/model``
For more information about supported URI schemes, see
`Referencing Artifacts <https://www.mlflow.org/docs/latest/tracking.html#
artifact-locations>`_.
dst_path: The local filesystem path to which to download the model artifact.
This directory must already exist. If unspecified, a local output
path will be created.
Returns:
A dictionary representing the OpenAI model.
log_model(model, task, artifact_path: str | None = None, conda_env=None, code_paths=None, registered_model_name=None, signature: mlflow.models.signature.ModelSignature = None, input_example: Union[pandas.core.frame.DataFrame, numpy.ndarray, dict, list, ForwardRef('csr_matrix'), ForwardRef('csc_matrix'), str, bytes, tuple] = None, await_registration_for=300, pip_requirements=None, extra_pip_requirements=None, metadata=None, prompts: list[str | mlflow.entities.model_registry.prompt.Prompt] | None = None, name: str | None = None, params: dict[str, typing.Any] | None = None, tags: dict[str, typing.Any] | None = None, model_type: str | None = None, step: int = 0, model_id: str | None = None, **kwargs)
.. Warning:: ``mlflow.openai.model.log_model`` is deprecated since 3.8.0. This method will be removed in a future release. Use ``mlflow.genai.register_prompt`` instead.
Log an OpenAI model as an MLflow artifact for the current run.
Args:
model: The OpenAI model name or reference instance, e.g.,
``openai.Model.retrieve("gpt-4o-mini")``.
task: The task the model is performing, e.g., ``openai.chat.completions`` or
``'chat.completions'``.
artifact_path: Deprecated. Use `name` instead.
conda_env: Either a dictionary representation of a Conda environment or the path to a conda
environment yaml file. If provided, this describes the environment this model should be run in.
At a minimum, it should specify the dependencies contained in `get_default_conda_env()`.
If ``None``, a conda environment with pip requirements inferred by
:func:`mlflow.models.infer_pip_requirements` is added
to the model. If the requirement inference fails, it falls back to using
`get_default_pip_requirements`. pip requirements from ``conda_env`` are written to a pip
``requirements.txt`` file and the full conda environment is written to ``conda.yaml``.
The following is an *example* dictionary representation of a conda environment::
{
"name": "mlflow-env",
"channels": ["conda-forge"],
"dependencies": [
"python=3.8.15",
{
"pip": [
"openai==x.y.z"
],
},
],
}
code_paths: A list of local filesystem paths to Python file dependencies (or directories
containing file dependencies). These files are *prepended* to the system path when the model
is loaded. Files declared as dependencies for a given model should have relative
imports declared from a common root path if multiple files are defined with import dependencies
between them to avoid import errors when loading the model.
For a detailed explanation of ``code_paths`` functionality, recommended usage patterns and
limitations, see the
`code_paths usage guide <https://mlflow.org/docs/latest/model/dependencies.html?highlight=code_paths#saving-extra-code-with-an-mlflow-model>`_.
registered_model_name: If given, create a model version under
``registered_model_name``, also creating a registered model if one
with the given name does not exist.
signature: :py:class:`ModelSignature <mlflow.models.ModelSignature>`
describes model input and output :py:class:`Schema <mlflow.types.Schema>`.
The model signature can be :py:func:`inferred <mlflow.models.infer_signature>`
from datasets with valid model input (e.g. the training dataset with target
column omitted) and valid model output (e.g. model predictions generated on
the training dataset), for example:
.. code-block:: python
from mlflow.models import infer_signature
train = df.drop_column("target_label")
predictions = ... # compute model predictions
signature = infer_signature(train, predictions)
input_example: one or several instances of valid model input. The input example is used
as a hint of what data to feed the model. It will be converted to a Pandas
DataFrame and then serialized to json using the Pandas split-oriented
format, or a numpy array where the example will be serialized to json
by converting it to a list. Bytes are base64-encoded. When the ``signature`` parameter is
``None``, the input example is used to infer a model signature.
await_registration_for: Number of seconds to wait for the model version to finish
being created and is in ``READY`` status. By default, the function
waits for five minutes. Specify 0 or None to skip waiting.
pip_requirements: Either an iterable of pip requirement strings
(e.g. ``["openai", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes the environment this model should be run in. If ``None``, a default list of requirements
is inferred by :func:`mlflow.models.infer_pip_requirements` from the current software environment.
If the requirement inference fails, it falls back to using `get_default_pip_requirements`.
Both requirements and constraints are automatically parsed and written to ``requirements.txt`` and
``constraints.txt`` files, respectively, and stored as part of the model. Requirements are also
written to the ``pip`` section of the model's conda environment (``conda.yaml``) file.
extra_pip_requirements: Either an iterable of pip
requirement strings
(e.g. ``["pandas", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes additional pip requirements that are appended to a default set of pip requirements
generated automatically based on the user's current software environment. Both requirements and
constraints are automatically parsed and written to ``requirements.txt`` and ``constraints.txt``
files, respectively, and stored as part of the model. Requirements are also written to the ``pip``
section of the model's conda environment (``conda.yaml``) file.
.. warning::
The following arguments can't be specified at the same time:
- ``conda_env``
- ``pip_requirements``
- ``extra_pip_requirements``
`This example <https://github.com/mlflow/mlflow/blob/master/examples/pip_requirements/pip_requirements.py>`_ demonstrates how to specify pip requirements using
``pip_requirements`` and ``extra_pip_requirements``.
metadata: Custom metadata dictionary passed to the model and stored in the MLmodel file.
prompts: A list of prompt URIs registered in the MLflow Prompt Registry, to be associated with the model.
Each prompt URI should be in the form ``prompt:/<name>/<version>``. The prompts should be
registered in the MLflow Prompt Registry before being associated with the model.
This will create a mutual link between the model and the prompt. The associated prompts can be
seen in the model's metadata stored in the MLmodel file. From the Prompt Registry UI, you can
navigate to the model as well.
.. code-block:: python
import mlflow
prompt_template = "Hi, {name}! How are you doing today?"
# Register a prompt in the MLflow Prompt Registry
mlflow.prompts.register_prompt("my_prompt", prompt_template, description="A simple prompt")
# Log a model with the registered prompt
with mlflow.start_run():
model_info = mlflow.pyfunc.log_model(
name=MyModel(),
name="model",
prompts=["prompt:/my_prompt/1"]
)
print(model_info.prompts)
# Output: ['prompt:/my_prompt/1']
# Load the prompt
prompt = mlflow.genai.load_prompt(model_info.prompts[0])
name: Model name.
params: A dictionary of parameters to log with the model.
tags: A dictionary of tags to log with the model.
model_type: The type of the model.
step: The step at which to log the model outputs and metrics
model_id: The ID of the model.
kwargs: Keyword arguments specific to the OpenAI task, such as the ``messages`` (see
:ref:`mlflow.openai.messages` for more details on this parameter)
or ``top_p`` value to use for chat completion.
Returns:
A :py:class:`ModelInfo <mlflow.models.model.ModelInfo>` instance that contains the
metadata of the logged model.
.. code-block:: python
:caption: Example
import mlflow
import openai
import pandas as pd
# Chat
with mlflow.start_run():
info = mlflow.openai.log_model(
model="gpt-4o-mini",
task=openai.chat.completions,
messages=[{"role": "user", "content": "Tell me a joke about {animal}."}],
name="model",
)
model = mlflow.pyfunc.load_model(info.model_uri)
df = pd.DataFrame({"animal": ["cats", "dogs"]})
print(model.predict(df))
# Embeddings
with mlflow.start_run():
info = mlflow.openai.log_model(
model="text-embedding-ada-002",
task=openai.embeddings,
name="embeddings",
)
model = mlflow.pyfunc.load_model(info.model_uri)
print(model.predict(["hello", "world"]))
save_model(model, task, path, conda_env=None, code_paths=None, mlflow_model=None, signature: mlflow.models.signature.ModelSignature = None, input_example: Union[pandas.core.frame.DataFrame, numpy.ndarray, dict, list, ForwardRef('csr_matrix'), ForwardRef('csc_matrix'), str, bytes, tuple] = None, pip_requirements=None, extra_pip_requirements=None, metadata=None, **kwargs)
.. Warning:: ``mlflow.openai.model.save_model`` is deprecated since 3.8.0. This method will be removed in a future release. Use ``mlflow.genai.register_prompt`` instead.
Save an OpenAI model to a path on the local file system.
Args:
model: The OpenAI model name.
task: The task the model is performing, e.g., ``openai.chat.completions`` or
``'chat.completions'``.
path: Local path where the model is to be saved.
conda_env: Either a dictionary representation of a Conda environment or the path to a conda
environment yaml file. If provided, this describes the environment this model should be run in.
At a minimum, it should specify the dependencies contained in `get_default_conda_env()`.
If ``None``, a conda environment with pip requirements inferred by
:func:`mlflow.models.infer_pip_requirements` is added
to the model. If the requirement inference fails, it falls back to using
`get_default_pip_requirements`. pip requirements from ``conda_env`` are written to a pip
``requirements.txt`` file and the full conda environment is written to ``conda.yaml``.
The following is an *example* dictionary representation of a conda environment::
{
"name": "mlflow-env",
"channels": ["conda-forge"],
"dependencies": [
"python=3.8.15",
{
"pip": [
"openai==x.y.z"
],
},
],
}
code_paths: A list of local filesystem paths to Python file dependencies (or directories
containing file dependencies). These files are *prepended* to the system path when the model
is loaded. Files declared as dependencies for a given model should have relative
imports declared from a common root path if multiple files are defined with import dependencies
between them to avoid import errors when loading the model.
For a detailed explanation of ``code_paths`` functionality, recommended usage patterns and
limitations, see the
`code_paths usage guide <https://mlflow.org/docs/latest/model/dependencies.html?highlight=code_paths#saving-extra-code-with-an-mlflow-model>`_.
mlflow_model: :py:mod:`mlflow.models.Model` this flavor is being added to.
signature: :py:class:`ModelSignature <mlflow.models.ModelSignature>`
describes model input and output :py:class:`Schema <mlflow.types.Schema>`.
The model signature can be :py:func:`inferred <mlflow.models.infer_signature>`
from datasets with valid model input (e.g. the training dataset with target
column omitted) and valid model output (e.g. model predictions generated on
the training dataset), for example:
.. code-block:: python
from mlflow.models import infer_signature
train = df.drop_column("target_label")
predictions = ... # compute model predictions
signature = infer_signature(train, predictions)
input_example: one or several instances of valid model input. The input example is used
as a hint of what data to feed the model. It will be converted to a Pandas
DataFrame and then serialized to json using the Pandas split-oriented
format, or a numpy array where the example will be serialized to json
by converting it to a list. Bytes are base64-encoded. When the ``signature`` parameter is
``None``, the input example is used to infer a model signature.
pip_requirements: Either an iterable of pip requirement strings
(e.g. ``["openai", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes the environment this model should be run in. If ``None``, a default list of requirements
is inferred by :func:`mlflow.models.infer_pip_requirements` from the current software environment.
If the requirement inference fails, it falls back to using `get_default_pip_requirements`.
Both requirements and constraints are automatically parsed and written to ``requirements.txt`` and
``constraints.txt`` files, respectively, and stored as part of the model. Requirements are also
written to the ``pip`` section of the model's conda environment (``conda.yaml``) file.
extra_pip_requirements: Either an iterable of pip
requirement strings
(e.g. ``["pandas", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes additional pip requirements that are appended to a default set of pip requirements
generated automatically based on the user's current software environment. Both requirements and
constraints are automatically parsed and written to ``requirements.txt`` and ``constraints.txt``
files, respectively, and stored as part of the model. Requirements are also written to the ``pip``
section of the model's conda environment (``conda.yaml``) file.
.. warning::
The following arguments can't be specified at the same time:
- ``conda_env``
- ``pip_requirements``
- ``extra_pip_requirements``
`This example <https://github.com/mlflow/mlflow/blob/master/examples/pip_requirements/pip_requirements.py>`_ demonstrates how to specify pip requirements using
``pip_requirements`` and ``extra_pip_requirements``.
metadata: Custom metadata dictionary passed to the model and stored in the MLmodel file.
kwargs: Keyword arguments specific to the OpenAI task, such as the ``messages`` (see
:ref:`mlflow.openai.messages` for more details on this parameter)
or ``top_p`` value to use for chat completion.
.. code-block:: python
import mlflow
import openai
# Chat
mlflow.openai.save_model(
model="gpt-4o-mini",
task=openai.chat.completions,
messages=[{"role": "user", "content": "Tell me a joke."}],
path="model",
)
# Completions
mlflow.openai.save_model(
model="text-davinci-002",
task=openai.completions,
prompt="{text}. The general sentiment of the text is",
path="model",
)
# Embeddings
mlflow.openai.save_model(
model="text-embedding-ada-002",
task=openai.embeddings,
path="model",
)
DATA
FLAVOR_NAME = 'openai'
__all__ = ['autolog', 'FLAVOR_NAME', 'load_model', 'log_model', 'save_...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\openai\__init__.py
mlflow.otel
Error rendering doc: No module named 'opentelemetry.exporter'
mlflow.override_feedback
Python Library Documentation: function override_feedback in module mlflow.tracing.assessment
override_feedback(*, trace_id: str, assessment_id: str, value: float | int | str | bool | dict[str, float | int | str | bool] | list[float | int | str | bool], rationale: str | None = None, source: mlflow.entities.assessment_source.AssessmentSource | None = None, metadata: dict[str, typing.Any] | None = None) -> mlflow.entities.assessment.Assessment
Overrides an existing feedback assessment with a new assessment. This API
logs a new assessment with the `overrides` field set to the provided assessment ID.
The original assessment will be marked as invalid, but will otherwise be unchanged.
This is useful when you want to correct an assessment generated by an LLM judge,
but want to preserve the original assessment for future judge fine-tuning.
If you want to mutate an assessment in-place, use :py:func:`update_assessment` instead.
Args:
trace_id: The ID of the trace.
assessment_id: The ID of the assessment to override.
value: The new value of the assessment.
rationale: The rationale of the new assessment.
source: The source of the new assessment.
metadata: Additional metadata for the new assessment.
Returns:
:py:class:`~mlflow.entities.Assessment`: The created assessment.
Examples:
.. code-block:: python
import mlflow
from mlflow.entities import AssessmentSource, AssessmentSourceType
# First, log an initial LLM-generated feedback as a simulation
llm_feedback = mlflow.log_feedback(
trace_id="tr-1234567890abcdef",
name="relevance",
value=0.6,
source=AssessmentSource(
source_type=AssessmentSourceType.LLM_JUDGE, source_id="gpt-4"
),
rationale="Response partially addresses the question",
)
# Later, a human reviewer disagrees and wants to override
corrected_assessment = mlflow.override_feedback(
trace_id="tr-1234567890abcdef",
assessment_id=llm_feedback.assessment_id,
value=0.9,
rationale="Response fully addresses the question with good examples",
source=AssessmentSource(
source_type=AssessmentSourceType.HUMAN, source_id="expert_reviewer@company.com"
),
metadata={
"override_reason": "LLM underestimated relevance",
"review_date": "2024-01-15",
"confidence": "high",
},
)
mlflow.paddle
Python Library Documentation: package mlflow.paddle in mlflow
NAME
mlflow.paddle
DESCRIPTION
The ``mlflow.paddle`` module provides an API for logging and loading paddle models.
This module exports paddle models with the following flavors:
Paddle (native) format
This is the main flavor that can be loaded back into paddle.
:py:mod:`mlflow.pyfunc`
Produced for use by generic pyfunc-based deployment tools and batch inference.
NOTE: The `mlflow.pyfunc` flavor is only added for paddle models that define `predict()`,
since `predict()` is required for pyfunc model inference.
PACKAGE CONTENTS
_paddle_autolog
DATA
DEFAULT_AWAIT_MAX_SLEEP_SECONDS = 300
FLAVOR_NAME = 'paddle'
LOG_MODEL_PARAM_DOCS = ParamDocs({'name': 'Model name.', 'conda_env': ...
MLMODEL_FILE_NAME = 'MLmodel'
ModelInputExample = typing.Union[pandas.core.frame.DataFrame, numpy......
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\paddle\__init__.py
mlflow.pmdarima
Python Library Documentation: package mlflow.pmdarima in mlflow
NAME
mlflow.pmdarima
DESCRIPTION
The ``mlflow.pmdarima`` module provides an API for logging and loading ``pmdarima`` models.
This module exports univariate ``pmdarima`` models in the following formats:
Pmdarima format
Serialized instance of a ``pmdarima`` model using pickle.
:py:mod:`mlflow.pyfunc`
Produced for use by generic pyfunc-based deployment tools and for batch auditing
of historical forecasts.
.. code-block:: python
:caption: Example
import pandas as pd
import mlflow
import mlflow.pyfunc
import pmdarima
from pmdarima import auto_arima
# Define a custom model class
class PmdarimaWrapper(mlflow.pyfunc.PythonModel):
def load_context(self, context):
self.model = context.artifacts["model"]
def predict(self, context, model_input):
return self.model.predict(n_periods=model_input.shape[0])
# Specify locations of source data and the model artifact
SOURCE_DATA = "https://raw.githubusercontent.com/facebook/prophet/master/examples/example_retail_sales.csv"
ARTIFACT_PATH = "model"
# Read data and recode columns
sales_data = pd.read_csv(SOURCE_DATA)
sales_data.rename(columns={"y": "sales", "ds": "date"}, inplace=True)
# Split the data into train/test
train_size = int(0.8 * len(sales_data))
train, _ = sales_data[:train_size], sales_data[train_size:]
# Create the model
model = pmdarima.auto_arima(train["sales"], seasonal=True, m=12)
# Log the model
with mlflow.start_run():
wrapper = PmdarimaWrapper()
mlflow.pyfunc.log_model(
name="model",
python_model=wrapper,
artifacts={"model": mlflow.pyfunc.model_to_dict(model)},
)
.. _Pmdarima:
http://alkaline-ml.com/pmdarima/
PACKAGE CONTENTS
DATA
DEFAULT_AWAIT_MAX_SLEEP_SECONDS = 300
FLAVOR_NAME = 'pmdarima'
INVALID_PARAMETER_VALUE = 1000
LOG_MODEL_PARAM_DOCS = ParamDocs({'name': 'Model name.', 'conda_env': ...
MLFLOW_ALLOW_PICKLE_DESERIALIZATION = 'MLFLOW_ALLOW_PICKLE_DESERIALIZA...
MLMODEL_FILE_NAME = 'MLmodel'
ModelInputExample = typing.Union[pandas.core.frame.DataFrame, numpy......
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\pmdarima\__init__.py
mlflow.projects
Python Library Documentation: package mlflow.projects in mlflow
NAME
mlflow.projects - The ``mlflow.projects`` module provides an API for running MLflow projects locally or remotely.
PACKAGE CONTENTS
_project_spec
backend (package)
databricks
docker
env_type
kubernetes
submitted_run
utils
SUBMODULES
loader
CLASSES
builtins.object
mlflow.projects.submitted_run.SubmittedRun
class SubmittedRun(builtins.object)
| Wrapper around an MLflow project run (e.g. a subprocess running an entry point
| command or a Databricks job run) and exposing methods for waiting on and cancelling the run.
| This class defines the interface that the MLflow project runner uses to manage the lifecycle
| of runs launched in different environments (e.g. runs launched locally or on Databricks).
|
| ``SubmittedRun`` is not thread-safe. That is, concurrent calls to wait() / cancel()
| from multiple threads may inadvertently kill resources (e.g. local processes) unrelated to the
| run.
|
| NOTE:
|
| Subclasses of ``SubmittedRun`` must expose a ``run_id`` member containing the
| run's MLflow run ID.
|
| Methods defined here:
|
| cancel(self)
| Cancel the run (interrupts the command subprocess, cancels the Databricks run, etc) and
| waits for it to terminate. The MLflow run status may not be set correctly
| upon run cancellation.
|
| get_status(self)
| Get status of the run.
|
| wait(self)
| Wait for the run to finish, returning True if the run succeeded and false otherwise. Note
| that in some cases (e.g. remote execution on Databricks), we may wait until the remote job
| completes rather than until the MLflow run completes.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| run_id
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FUNCTIONS
run(uri, entry_point='main', version=None, parameters=None, docker_args=None, experiment_name=None, experiment_id=None, backend='local', backend_config=None, storage_dir=None, synchronous=True, run_id=None, run_name=None, env_manager=None, build_image=False, docker_auth=None)
Run an MLflow project. The project can be local or stored at a Git URI.
MLflow provides built-in support for running projects locally or remotely on a Databricks or
Kubernetes cluster. You can also run projects against other targets by installing an appropriate
third-party plugin. See `Community Plugins <../plugins.html#community-plugins>`_ for more
information.
For information on using this method in chained workflows, see `Building Multistep Workflows
<../projects.html#building-multistep-workflows>`_.
Raises:
:py:class:`mlflow.exceptions.ExecutionException` If a run launched in blocking mode
is unsuccessful.
Args:
uri: URI of project to run. A local filesystem path
or a Git repository URI (e.g. https://github.com/mlflow/mlflow-example)
pointing to a project directory containing an MLproject file.
entry_point: Entry point to run within the project. If no entry point with the specified
name is found, runs the project file ``entry_point`` as a script,
using "python" to run ``.py`` files and the default shell (specified by
environment variable ``$SHELL``) to run ``.sh`` files.
version: For Git-based projects, either a commit hash or a branch name.
parameters: Parameters (dictionary) for the entry point command.
docker_args: Arguments (dictionary) for the docker command.
experiment_name: Name of experiment under which to launch the run.
experiment_id: ID of experiment under which to launch the run.
backend: Execution backend for the run: MLflow provides built-in support for "local",
"databricks", and "kubernetes" (experimental) backends. If running against
Databricks, will run against a Databricks workspace determined as follows:
if a Databricks tracking URI of the form ``databricks://profile`` has been set
(e.g. by setting the MLFLOW_TRACKING_URI environment variable), will run
against the workspace specified by <profile>. Otherwise, runs against the
workspace specified by the default Databricks CLI profile.
backend_config: A dictionary, or a path to a JSON file (must end in '.json'), which will
be passed as config to the backend. The exact content which should be
provided is different for each execution backend and is documented
at https://www.mlflow.org/docs/latest/projects.html.
storage_dir: Used only if ``backend`` is "local". MLflow downloads artifacts from
distributed URIs passed to parameters of type ``path`` to subdirectories of
``storage_dir``.
synchronous: Whether to block while waiting for a run to complete. Defaults to True.
Note that if ``synchronous`` is False and ``backend`` is "local", this
method will return, but the current process will block when exiting until
the local run completes. If the current process is interrupted, any
asynchronous runs launched via this method will be terminated. If
``synchronous`` is True and the run fails, the current process will
error out as well.
run_id: Note: this argument is used internally by the MLflow project APIs and should
not be specified. If specified, the run ID will be used instead of
creating a new run.
run_name: The name to give the MLflow Run associated with the project execution.
If ``None``, the MLflow Run name is left unset.
env_manager: Specify an environment manager to create a new environment for the run and
install project dependencies within that environment. The following values
are supported:
- local: use the local environment
- virtualenv: use virtualenv (and pyenv for Python version management)
- uv: use uv
- conda: use conda
If unspecified, MLflow automatically determines the environment manager to
use by inspecting files in the project directory. For example, if
``python_env.yaml`` is present, virtualenv will be used.
build_image: Whether to build a new docker image of the project or to reuse an existing
image. Default: False (reuse an existing image)
docker_auth: A dictionary representing information to authenticate with a Docker
registry. See `docker.client.DockerClient.login
<https://docker-py.readthedocs.io/en/stable/client.html#docker.client.DockerClient.login>`_
for available options.
Returns:
:py:class:`mlflow.projects.SubmittedRun` exposing information (e.g. run ID)
about the launched run.
.. code-block:: python
:caption: Example
import mlflow
project_uri = "https://github.com/mlflow/mlflow-example"
params = {"alpha": 0.5, "l1_ratio": 0.01}
# Run MLflow project and create a reproducible conda environment
# on a local host
mlflow.run(project_uri, parameters=params)
.. code-block:: text
:caption: Output
...
...
Elasticnet model (alpha=0.500000, l1_ratio=0.010000):
RMSE: 0.788347345611717
MAE: 0.6155576449938276
R2: 0.19729662005412607
... mlflow.projects: === Run (ID '6a5109febe5e4a549461e149590d0a7c') succeeded ===
DATA
__all__ = ['run', 'SubmittedRun']
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\projects\__init__.py
mlflow.prompt
Python Library Documentation: package mlflow.prompt in mlflow
NAME
mlflow.prompt
PACKAGE CONTENTS
constants
promptlab_model
registry_utils
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\prompt\__init__.py
mlflow.prophet
Python Library Documentation: package mlflow.prophet in mlflow
NAME
mlflow.prophet
DESCRIPTION
The ``mlflow.prophet`` module provides an API for logging and loading Prophet models.
This module exports univariate Prophet models in the following flavors:
Prophet (native) format
This is the main flavor that can be accessed with Prophet APIs.
:py:mod:`mlflow.pyfunc`
Produced for use by generic pyfunc-based deployment tools and for batch auditing
of historical forecasts.
.. _Prophet:
https://facebook.github.io/prophet/docs/quick_start.html#python-api
PACKAGE CONTENTS
DATA
DEFAULT_AWAIT_MAX_SLEEP_SECONDS = 300
FLAVOR_NAME = 'prophet'
LOG_MODEL_PARAM_DOCS = ParamDocs({'name': 'Model name.', 'conda_env': ...
MLMODEL_FILE_NAME = 'MLmodel'
ModelInputExample = typing.Union[pandas.core.frame.DataFrame, numpy......
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\prophet\__init__.py
mlflow.protos
Python Library Documentation: package mlflow.protos in mlflow
NAME
mlflow.protos
PACKAGE CONTENTS
assessments_pb2
databricks_artifacts_pb2
databricks_exception_with_details_pb2
databricks_filesystem_service_pb2
databricks_managed_catalog_messages_pb2
databricks_managed_catalog_service_pb2
databricks_pb2
databricks_tracing_pb2
databricks_uc_registry_messages_pb2
databricks_uc_registry_service_pb2
datasets_pb2
facet_feature_statistics_pb2
internal_pb2
issues_pb2
jobs_pb2
label_schemas_pb2
mlflow_artifacts_pb2
model_registry_pb2
prompt_optimization_pb2
review_queues_pb2
scalapb (package)
service_pb2
unity_catalog_messages_pb2
unity_catalog_prompt_messages_pb2
unity_catalog_prompt_messages_pb2_grpc
unity_catalog_prompt_service_pb2
unity_catalog_prompt_service_pb2_grpc
unity_catalog_service_pb2
webhooks_pb2
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\protos\__init__.py
mlflow.pydantic_ai
Python Library Documentation: package mlflow.pydantic_ai in mlflow
NAME
mlflow.pydantic_ai
PACKAGE CONTENTS
autolog
autolog_v2
utils
DATA
FLAVOR_NAME = 'pydantic_ai'
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\pydantic_ai\__init__.py
mlflow.pyfunc
Python Library Documentation: package mlflow.pyfunc in mlflow
NAME
mlflow.pyfunc
DESCRIPTION
The ``python_function`` model flavor serves as a default model interface for MLflow Python models.
Any MLflow Python model is expected to be loadable as a ``python_function`` model.
In addition, the ``mlflow.pyfunc`` module defines a generic :ref:`filesystem format
<pyfunc-filesystem-format>` for Python models and provides utilities for saving to and loading from
this format. The format is self contained in the sense that it includes all necessary information
for anyone to load it and use it. Dependencies are either stored directly with the model or
referenced via a Conda environment.
The ``mlflow.pyfunc`` module also defines utilities for creating custom ``pyfunc`` models
using frameworks and inference logic that may not be natively included in MLflow. See
:ref:`pyfunc-create-custom`.
.. _pyfunc-inference-api:
*************
Inference API
*************
Python function models are loaded as an instance of :py:class:`PyFuncModel
<mlflow.pyfunc.PyFuncModel>`, which is an MLflow wrapper around the model implementation and model
metadata (MLmodel file). You can score the model by calling the :py:func:`predict()
<mlflow.pyfunc.PyFuncModel.predict>` method, which has the following signature::
predict(
model_input: [pandas.DataFrame, numpy.ndarray, scipy.sparse.(csc_matrix | csr_matrix),
List[Any], Dict[str, Any], pyspark.sql.DataFrame]
) -> [numpy.ndarray | pandas.(Series | DataFrame) | List | Dict | pyspark.sql.DataFrame]
All PyFunc models will support `pandas.DataFrame` as input and PyFunc deep learning models will
also support tensor inputs in the form of Dict[str, numpy.ndarray] (named tensors) and
`numpy.ndarrays` (unnamed tensors).
Here are some examples of supported inference types, assuming we have the correct ``model`` object
loaded.
.. list-table::
:widths: 30 70
:header-rows: 1
:class: wrap-table
* - Input Type
- Example
* - ``pandas.DataFrame``
-
.. code-block:: python
import pandas as pd
x_new = pd.DataFrame(dict(x1=[1, 2, 3], x2=[4, 5, 6]))
model.predict(x_new)
* - ``numpy.ndarray``
-
.. code-block:: python
import numpy as np
x_new = np.array([[1, 4][2, 5], [3, 6]])
model.predict(x_new)
* - ``scipy.sparse.csc_matrix`` or ``scipy.sparse.csr_matrix``
-
.. code-block:: python
import scipy
x_new = scipy.sparse.csc_matrix([[1, 2, 3], [4, 5, 6]])
model.predict(x_new)
x_new = scipy.sparse.csr_matrix([[1, 2, 3], [4, 5, 6]])
model.predict(x_new)
* - python ``List``
-
.. code-block:: python
x_new = [[1, 4], [2, 5], [3, 6]]
model.predict(x_new)
* - python ``Dict``
-
.. code-block:: python
x_new = dict(x1=[1, 2, 3], x2=[4, 5, 6])
model.predict(x_new)
* - ``pyspark.sql.DataFrame``
-
.. code-block:: python
from pyspark.sql import SparkSession
spark = SparkSession.builder.getOrCreate()
data = [(1, 4), (2, 5), (3, 6)] # List of tuples
x_new = spark.createDataFrame(data, ["x1", "x2"]) # Specify column name
model.predict(x_new)
.. _pyfunc-filesystem-format:
*****************
Filesystem format
*****************
The Pyfunc format is defined as a directory structure containing all required data, code, and
configuration::
./dst-path/
./MLmodel: configuration
<code>: code packaged with the model (specified in the MLmodel file)
<data>: data packaged with the model (specified in the MLmodel file)
<env>: Conda environment definition (specified in the MLmodel file)
The directory structure may contain additional contents that can be referenced by the ``MLmodel``
configuration.
.. _pyfunc-model-config:
MLModel configuration
#####################
A Python model contains an ``MLmodel`` file in **python_function** format in its root with the
following parameters:
- loader_module [required]:
Python module that can load the model. Expected as module identifier
e.g. ``mlflow.sklearn``, it will be imported using ``importlib.import_module``.
The imported module must contain a function with the following signature::
_load_pyfunc(path: string) -> <pyfunc model implementation>
The path argument is specified by the ``data`` parameter and may refer to a file or
directory. The model implementation is expected to be an object with a
``predict`` method with the following signature::
predict(
model_input: [pandas.DataFrame, numpy.ndarray,
scipy.sparse.(csc_matrix | csr_matrix), List[Any], Dict[str, Any]],
pyspark.sql.DataFrame
) -> [numpy.ndarray | pandas.(Series | DataFrame) | List | Dict | pyspark.sql.DataFrame]
- code [optional]:
Relative path to a directory containing the code packaged with this model.
All files and directories inside this directory are added to the Python path
prior to importing the model loader.
- data [optional]:
Relative path to a file or directory containing model data.
The path is passed to the model loader.
- env [optional]:
Relative path to an exported Conda environment. If present this environment
should be activated prior to running the model.
- Optionally, any additional parameters necessary for interpreting the serialized model in
``pyfunc`` format.
.. rubric:: Example
::
tree example/sklearn_iris/mlruns/run1/outputs/linear-lr
::
├── MLmodel
├── code
│ ├── sklearn_iris.py
│
├── data
│ └── model.pkl
└── mlflow_env.yml
::
cat example/sklearn_iris/mlruns/run1/outputs/linear-lr/MLmodel
::
python_function:
code: code
data: data/model.pkl
loader_module: mlflow.sklearn
env: mlflow_env.yml
main: sklearn_iris
.. _pyfunc-create-custom:
**********************************
Models From Code for Custom Models
**********************************
.. tip::
MLflow 2.12.2 introduced the feature "models from code", which greatly simplifies the process
of serializing and deploying custom models through the use of script serialization. It is
strongly recommended to migrate custom model implementations to this new paradigm to avoid the
limitations and complexity of serializing with cloudpickle.
You can learn more about models from code within the
`Models From Code Guide <../model/models-from-code.html>`_.
The section below illustrates the process of using the legacy serializer for custom Pyfunc models.
Models from code will provide a far simpler experience for logging of your models.
******************************
Creating custom Pyfunc models
******************************
MLflow's persistence modules provide convenience functions for creating models with the
``pyfunc`` flavor in a variety of machine learning frameworks (scikit-learn, Keras, Pytorch, and
more); however, they do not cover every use case. For example, you may want to create an MLflow
model with the ``pyfunc`` flavor using a framework that MLflow does not natively support.
Alternatively, you may want to build an MLflow model that executes custom logic when evaluating
queries, such as preprocessing and postprocessing routines. Therefore, ``mlflow.pyfunc``
provides utilities for creating ``pyfunc`` models from arbitrary code and model data.
The :meth:`save_model()` and :meth:`log_model()` methods are designed to support multiple workflows
for creating custom ``pyfunc`` models that incorporate custom inference logic and artifacts
that the logic may require.
An `artifact` is a file or directory, such as a serialized model or a CSV. For example, a
serialized TensorFlow graph is an artifact. An MLflow model directory is also an artifact.
.. _pyfunc-create-custom-workflows:
Workflows
#########
:meth:`save_model()` and :meth:`log_model()` support the following workflows:
1. Programmatically defining a new MLflow model, including its attributes and artifacts.
Given a set of artifact URIs, :meth:`save_model()` and :meth:`log_model()` can
automatically download artifacts from their URIs and create an MLflow model directory.
In this case, you must define a Python class which inherits from :class:`~PythonModel`,
defining ``predict()`` and, optionally, ``load_context()``. An instance of this class is
specified via the ``python_model`` parameter; it is automatically serialized and deserialized
as a Python class, including all of its attributes.
2. Interpreting pre-existing data as an MLflow model.
If you already have a directory containing model data, :meth:`save_model()` and
:meth:`log_model()` can import the data as an MLflow model. The ``data_path`` parameter
specifies the local filesystem path to the directory containing model data.
In this case, you must provide a Python module, called a `loader module`. The
loader module defines a ``_load_pyfunc()`` method that performs the following tasks:
- Load data from the specified ``data_path``. For example, this process may include
deserializing pickled Python objects or models or parsing CSV files.
- Construct and return a pyfunc-compatible model wrapper. As in the first
use case, this wrapper must define a ``predict()`` method that is used to evaluate
queries. ``predict()`` must adhere to the :ref:`pyfunc-inference-api`.
The ``loader_module`` parameter specifies the name of your loader module.
For an example loader module implementation, refer to the `loader module
implementation in mlflow.sklearn <https://github.com/mlflow/mlflow/blob/
74d75109aaf2975f5026104d6125bb30f4e3f744/mlflow/sklearn.py#L200-L205>`_.
.. _pyfunc-create-custom-selecting-workflow:
Which workflow is right for my use case?
########################################
We consider the first workflow to be more user-friendly and generally recommend it for the
following reasons:
- It automatically resolves and collects specified model artifacts.
- It automatically serializes and deserializes the ``python_model`` instance and all of
its attributes, reducing the amount of user logic that is required to load the model
- You can create Models using logic that is defined in the ``__main__`` scope. This allows
custom models to be constructed in interactive environments, such as notebooks and the Python
REPL.
You may prefer the second, lower-level workflow for the following reasons:
- Inference logic is always persisted as code, rather than a Python object. This makes logic
easier to inspect and modify later.
- If you have already collected all of your model data in a single location, the second
workflow allows it to be saved in MLflow format directly, without enumerating constituent
artifacts.
******************************************
Function-based Model vs Class-based Model
******************************************
When creating custom PyFunc models, you can choose between two different interfaces:
a function-based model and a class-based model. In short, a function-based model is simply a
python function that does not take additional params. The class-based model, on the other hand,
is subclass of ``PythonModel`` that supports several required and optional
methods. If your use case is simple and fits within a single predict function, a function-based
approach is recommended. If you need more power, such as custom serialization, custom data
processing, or to override additional methods, you should use the class-based implementation.
Before looking at code examples, it's important to note that both methods are serialized via
`cloudpickle <https://github.com/cloudpipe/cloudpickle>`_. cloudpickle can serialize Python
functions, lambda functions, and locally defined classes and functions inside other functions. This
makes cloudpickle especially useful for parallel and distributed computing where code objects need
to be sent over network to execute on remote workers, which is a common deployment paradigm for
MLflow.
That said, cloudpickle has some limitations.
- **Environment Dependency**: cloudpickle does not capture the full execution environment, so in
MLflow we must pass ``pip_requirements``, ``extra_pip_requirements``, or an ``input_example``,
the latter of which is used to infer environment dependencies. For more, refer to
`the model dependency docs <https://mlflow.org/docs/latest/model/dependencies.html>`_.
- **Object Support**: cloudpickle does not serialize objects outside of the Python data model.
Some relevant examples include raw files and database connections. If your program depends on
these, be sure to log ways to reference these objects along with your model.
Function-based Model
####################
If you're looking to serialize a simple python function without additional dependent methods, you
can simply log a predict method via the keyword argument ``python_model``.
.. note::
Function-based model only supports a function with a single input argument. If you would like
to pass more arguments or additional inference parameters, please use the class-based model
below.
.. code-block:: python
import mlflow
import pandas as pd
# Define a simple function to log
def predict(model_input):
return model_input.apply(lambda x: x * 2)
# Save the function as a model
with mlflow.start_run():
mlflow.pyfunc.log_model(name="model", python_model=predict, pip_requirements=["pandas"])
run_id = mlflow.active_run().info.run_id
# Load the model from the tracking server and perform inference
model = mlflow.pyfunc.load_model(f"runs:/{run_id}/model")
x_new = pd.Series([1, 2, 3])
prediction = model.predict(x_new)
print(prediction)
Class-based Model
#################
If you're looking to serialize a more complex object, for instance a class that handles
preprocessing, complex prediction logic, or custom serialization, you should subclass the
``PythonModel`` class. MLflow has tutorials on building custom PyFunc models, as shown
`here <https://mlflow.org/docs/latest/traditional-ml/creating-custom-pyfunc/index.html>`_,
so instead of duplicating that information, in this example we'll recreate the above functionality
to highlight the differences. Note that this PythonModel implementation is overly complex and
we would recommend using the functional-based Model instead for this simple case.
.. code-block:: python
import mlflow
import pandas as pd
class MyModel(mlflow.pyfunc.PythonModel):
def predict(self, context, model_input, params=None):
return [x * 2 for x in model_input]
# Save the function as a model
with mlflow.start_run():
mlflow.pyfunc.log_model(name="model", python_model=MyModel(), pip_requirements=["pandas"])
run_id = mlflow.active_run().info.run_id
# Load the model from the tracking server and perform inference
model = mlflow.pyfunc.load_model(f"runs:/{run_id}/model")
x_new = pd.Series([1, 2, 3])
print(f"Prediction:
{model.predict(x_new)}")
The primary difference between the this implementation and the function-based implementation above
is that the predict method is wrapped with a class, has the ``self`` parameter,
and has the ``params`` parameter that defaults to None. Note that function-based models don't
support additional params.
In summary, use the function-based Model when you have a simple function to serialize.
If you need more power, use the class-based model.
PACKAGE CONTENTS
_mlflow_pyfunc_backend_predict
backend
context
dbconnect_artifact_cache
loaders (package)
model
scoring_server (package)
spark_model_cache
stdin_server
utils (package)
CLASSES
builtins.object
EnvType
PyFuncModel
google._upb._message.Message(builtins.object)
databricks_uc_registry_messages_pb2.Entity(google._upb._message.Message, google.protobuf.message.Message)
databricks_uc_registry_messages_pb2.Job(google._upb._message.Message, google.protobuf.message.Message)
databricks_uc_registry_messages_pb2.LineageHeaderInfo(google._upb._message.Message, google.protobuf.message.Message)
databricks_uc_registry_messages_pb2.Notebook(google._upb._message.Message, google.protobuf.message.Message)
google.protobuf.message.Message(builtins.object)
databricks_uc_registry_messages_pb2.Entity(google._upb._message.Message, google.protobuf.message.Message)
databricks_uc_registry_messages_pb2.Job(google._upb._message.Message, google.protobuf.message.Message)
databricks_uc_registry_messages_pb2.LineageHeaderInfo(google._upb._message.Message, google.protobuf.message.Message)
databricks_uc_registry_messages_pb2.Notebook(google._upb._message.Message, google.protobuf.message.Message)
class Entity(google._upb._message.Message, google.protobuf.message.Message)
| Method resolution order:
| Entity
| google._upb._message.Message
| google.protobuf.message.Message
| builtins.object
|
| Data and other attributes defined here:
|
| DESCRIPTOR = <google._upb._message.Descriptor object>
|
| ----------------------------------------------------------------------
| Methods inherited from google._upb._message.Message:
|
| ByteSize(...)
| Returns the size of the message in bytes.
|
| Clear(...)
| Clears the message.
|
| ClearExtension(...)
| Clears a message field.
|
| ClearField(...)
| Clears a message field.
|
| CopyFrom(...)
| Copies a protocol message into the current message.
|
| DiscardUnknownFields(...)
| Discards the unknown fields.
|
| FindInitializationErrors(...)
| Finds unset required fields.
|
| HasExtension(...)
| Checks if a message field is set.
|
| HasField(...)
| Checks if a message field is set.
|
| IsInitialized(...)
| Checks if all required fields of a protocol message are set.
|
| ListFields(...)
| Lists all set fields of a message.
|
| MergeFrom(...)
| Merges a protocol message into the current message.
|
| MergeFromString(...)
| Merges a serialized message into the current message.
|
| ParseFromString(...)
| Parses a serialized message into the current message.
|
| SerializePartialToString(...)
| Serializes the message to a string, even if it isn't initialized.
|
| SerializeToString(...)
| Serializes the message to a string, only for initialized messages.
|
| SetInParent(...)
| Sets the has bit of the given field in its parent message.
|
| UnknownFields(...)
| Parse unknown field set
|
| WhichOneof(...)
| Returns the name of the field set inside a oneof, or None if no field is set.
|
| __contains__(...)
| Checks if a message field is set.
|
| __deepcopy__(...)
| Makes a deep copy of the class.
|
| __delattr__(self, name, /)
| Implement delattr(self, name).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __repr__(self, /)
| Return repr(self).
|
| __setattr__(self, name, value, /)
| Implement setattr(self, name, value).
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Class methods inherited from google._upb._message.Message:
|
| FromString(...)
| Creates new method instance from given serialized data.
|
| ----------------------------------------------------------------------
| Static methods inherited from google._upb._message.Message:
|
| __new__(*args, **kwargs) class method of google._upb._message.Message
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from google._upb._message.Message:
|
| Extensions
| Extension dict
|
| ----------------------------------------------------------------------
| Methods inherited from google.protobuf.message.Message:
|
| __dir__(self)
| Provides the list of all accessible Message attributes.
|
| __getstate__(self)
| Support the pickle protocol.
|
| __reduce__(self)
| Helper for pickle.
|
| __setstate__(self, state)
| Support the pickle protocol.
|
| __unicode__(self)
| Outputs a human-readable representation of the message.
class EnvType(builtins.object)
| Methods defined here:
|
| __init__(self)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| CONDA = 'conda'
|
| VIRTUALENV = 'virtualenv'
class Job(google._upb._message.Message, google.protobuf.message.Message)
| Method resolution order:
| Job
| google._upb._message.Message
| google.protobuf.message.Message
| builtins.object
|
| Data and other attributes defined here:
|
| DESCRIPTOR = <google._upb._message.Descriptor object>
|
| ----------------------------------------------------------------------
| Methods inherited from google._upb._message.Message:
|
| ByteSize(...)
| Returns the size of the message in bytes.
|
| Clear(...)
| Clears the message.
|
| ClearExtension(...)
| Clears a message field.
|
| ClearField(...)
| Clears a message field.
|
| CopyFrom(...)
| Copies a protocol message into the current message.
|
| DiscardUnknownFields(...)
| Discards the unknown fields.
|
| FindInitializationErrors(...)
| Finds unset required fields.
|
| HasExtension(...)
| Checks if a message field is set.
|
| HasField(...)
| Checks if a message field is set.
|
| IsInitialized(...)
| Checks if all required fields of a protocol message are set.
|
| ListFields(...)
| Lists all set fields of a message.
|
| MergeFrom(...)
| Merges a protocol message into the current message.
|
| MergeFromString(...)
| Merges a serialized message into the current message.
|
| ParseFromString(...)
| Parses a serialized message into the current message.
|
| SerializePartialToString(...)
| Serializes the message to a string, even if it isn't initialized.
|
| SerializeToString(...)
| Serializes the message to a string, only for initialized messages.
|
| SetInParent(...)
| Sets the has bit of the given field in its parent message.
|
| UnknownFields(...)
| Parse unknown field set
|
| WhichOneof(...)
| Returns the name of the field set inside a oneof, or None if no field is set.
|
| __contains__(...)
| Checks if a message field is set.
|
| __deepcopy__(...)
| Makes a deep copy of the class.
|
| __delattr__(self, name, /)
| Implement delattr(self, name).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __repr__(self, /)
| Return repr(self).
|
| __setattr__(self, name, value, /)
| Implement setattr(self, name, value).
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Class methods inherited from google._upb._message.Message:
|
| FromString(...)
| Creates new method instance from given serialized data.
|
| ----------------------------------------------------------------------
| Static methods inherited from google._upb._message.Message:
|
| __new__(*args, **kwargs) class method of google._upb._message.Message
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from google._upb._message.Message:
|
| Extensions
| Extension dict
|
| ----------------------------------------------------------------------
| Methods inherited from google.protobuf.message.Message:
|
| __dir__(self)
| Provides the list of all accessible Message attributes.
|
| __getstate__(self)
| Support the pickle protocol.
|
| __reduce__(self)
| Helper for pickle.
|
| __setstate__(self, state)
| Support the pickle protocol.
|
| __unicode__(self)
| Outputs a human-readable representation of the message.
class LineageHeaderInfo(google._upb._message.Message, google.protobuf.message.Message)
| Method resolution order:
| LineageHeaderInfo
| google._upb._message.Message
| google.protobuf.message.Message
| builtins.object
|
| Data and other attributes defined here:
|
| DESCRIPTOR = <google._upb._message.Descriptor object>
|
| ----------------------------------------------------------------------
| Methods inherited from google._upb._message.Message:
|
| ByteSize(...)
| Returns the size of the message in bytes.
|
| Clear(...)
| Clears the message.
|
| ClearExtension(...)
| Clears a message field.
|
| ClearField(...)
| Clears a message field.
|
| CopyFrom(...)
| Copies a protocol message into the current message.
|
| DiscardUnknownFields(...)
| Discards the unknown fields.
|
| FindInitializationErrors(...)
| Finds unset required fields.
|
| HasExtension(...)
| Checks if a message field is set.
|
| HasField(...)
| Checks if a message field is set.
|
| IsInitialized(...)
| Checks if all required fields of a protocol message are set.
|
| ListFields(...)
| Lists all set fields of a message.
|
| MergeFrom(...)
| Merges a protocol message into the current message.
|
| MergeFromString(...)
| Merges a serialized message into the current message.
|
| ParseFromString(...)
| Parses a serialized message into the current message.
|
| SerializePartialToString(...)
| Serializes the message to a string, even if it isn't initialized.
|
| SerializeToString(...)
| Serializes the message to a string, only for initialized messages.
|
| SetInParent(...)
| Sets the has bit of the given field in its parent message.
|
| UnknownFields(...)
| Parse unknown field set
|
| WhichOneof(...)
| Returns the name of the field set inside a oneof, or None if no field is set.
|
| __contains__(...)
| Checks if a message field is set.
|
| __deepcopy__(...)
| Makes a deep copy of the class.
|
| __delattr__(self, name, /)
| Implement delattr(self, name).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __repr__(self, /)
| Return repr(self).
|
| __setattr__(self, name, value, /)
| Implement setattr(self, name, value).
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Class methods inherited from google._upb._message.Message:
|
| FromString(...)
| Creates new method instance from given serialized data.
|
| ----------------------------------------------------------------------
| Static methods inherited from google._upb._message.Message:
|
| __new__(*args, **kwargs) class method of google._upb._message.Message
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from google._upb._message.Message:
|
| Extensions
| Extension dict
|
| ----------------------------------------------------------------------
| Methods inherited from google.protobuf.message.Message:
|
| __dir__(self)
| Provides the list of all accessible Message attributes.
|
| __getstate__(self)
| Support the pickle protocol.
|
| __reduce__(self)
| Helper for pickle.
|
| __setstate__(self, state)
| Support the pickle protocol.
|
| __unicode__(self)
| Outputs a human-readable representation of the message.
class Notebook(google._upb._message.Message, google.protobuf.message.Message)
| Method resolution order:
| Notebook
| google._upb._message.Message
| google.protobuf.message.Message
| builtins.object
|
| Data and other attributes defined here:
|
| DESCRIPTOR = <google._upb._message.Descriptor object>
|
| ----------------------------------------------------------------------
| Methods inherited from google._upb._message.Message:
|
| ByteSize(...)
| Returns the size of the message in bytes.
|
| Clear(...)
| Clears the message.
|
| ClearExtension(...)
| Clears a message field.
|
| ClearField(...)
| Clears a message field.
|
| CopyFrom(...)
| Copies a protocol message into the current message.
|
| DiscardUnknownFields(...)
| Discards the unknown fields.
|
| FindInitializationErrors(...)
| Finds unset required fields.
|
| HasExtension(...)
| Checks if a message field is set.
|
| HasField(...)
| Checks if a message field is set.
|
| IsInitialized(...)
| Checks if all required fields of a protocol message are set.
|
| ListFields(...)
| Lists all set fields of a message.
|
| MergeFrom(...)
| Merges a protocol message into the current message.
|
| MergeFromString(...)
| Merges a serialized message into the current message.
|
| ParseFromString(...)
| Parses a serialized message into the current message.
|
| SerializePartialToString(...)
| Serializes the message to a string, even if it isn't initialized.
|
| SerializeToString(...)
| Serializes the message to a string, only for initialized messages.
|
| SetInParent(...)
| Sets the has bit of the given field in its parent message.
|
| UnknownFields(...)
| Parse unknown field set
|
| WhichOneof(...)
| Returns the name of the field set inside a oneof, or None if no field is set.
|
| __contains__(...)
| Checks if a message field is set.
|
| __deepcopy__(...)
| Makes a deep copy of the class.
|
| __delattr__(self, name, /)
| Implement delattr(self, name).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __repr__(self, /)
| Return repr(self).
|
| __setattr__(self, name, value, /)
| Implement setattr(self, name, value).
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Class methods inherited from google._upb._message.Message:
|
| FromString(...)
| Creates new method instance from given serialized data.
|
| ----------------------------------------------------------------------
| Static methods inherited from google._upb._message.Message:
|
| __new__(*args, **kwargs) class method of google._upb._message.Message
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from google._upb._message.Message:
|
| Extensions
| Extension dict
|
| ----------------------------------------------------------------------
| Methods inherited from google.protobuf.message.Message:
|
| __dir__(self)
| Provides the list of all accessible Message attributes.
|
| __getstate__(self)
| Support the pickle protocol.
|
| __reduce__(self)
| Helper for pickle.
|
| __setstate__(self, state)
| Support the pickle protocol.
|
| __unicode__(self)
| Outputs a human-readable representation of the message.
class PyFuncModel(builtins.object)
| PyFuncModel(model_meta: mlflow.models.model.Model, model_impl: Any, predict_fn: str = 'predict', predict_stream_fn: str | None = None, model_id: str | None = None)
|
| MLflow 'python function' model.
|
| Wrapper around model implementation and metadata. This class is not meant to be constructed
| directly. Instead, instances of this class are constructed and returned from
| :py:func:`load_model() <mlflow.pyfunc.load_model>`.
|
| ``model_impl`` can be any Python object that implements the `Pyfunc interface
| <https://mlflow.org/docs/latest/python_api/mlflow.pyfunc.html#pyfunc-inference-api>`_, and is
| returned by invoking the model's ``loader_module``.
|
| ``model_meta`` contains model metadata loaded from the MLmodel file.
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, model_meta: mlflow.models.model.Model, model_impl: Any, predict_fn: str = 'predict', predict_stream_fn: str | None = None, model_id: str | None = None)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| get_raw_model(self)
| Get the underlying raw model if the model wrapper implemented `get_raw_model` function.
|
| predict(self, data: Union[pandas.core.frame.DataFrame, pandas.core.series.Series, numpy.ndarray, ForwardRef('csc_matrix'), ForwardRef('csr_matrix'), List[Any], Dict[str, Any], datetime.datetime, bool, bytes, float, int, str], params: dict[str, typing.Any] | None = None) -> pandas.core.frame.DataFrame | pandas.core.series.Series | numpy.ndarray | list | str | dict[str, typing.Any]
|
| predict_stream(self, data: dict[str, typing.Any] | bool | bytes | float | int | str, params: dict[str, typing.Any] | None = None) -> Iterator[dict[str, Any] | str]
|
| unwrap_python_model(self)
| Unwrap the underlying Python model object.
|
| This method is useful for accessing custom model functions, while still being able to
| leverage the MLflow designed workflow through the `predict()` method.
|
| Returns:
| The underlying wrapped model object
|
| .. code-block:: python
| :test:
| :caption: Example
|
| import mlflow
|
|
| # define a custom model
| class MyModel(mlflow.pyfunc.PythonModel):
| def predict(self, context, model_input, params=None):
| return self.my_custom_function(model_input, params)
|
| def my_custom_function(self, model_input, params=None):
| # do something with the model input
| return 0
|
|
| some_input = 1
| # save the model
| with mlflow.start_run():
| model_info = mlflow.pyfunc.log_model(name="model", python_model=MyModel())
|
| # load the model
| loaded_model = mlflow.pyfunc.load_model(model_uri=model_info.model_uri)
| print(type(loaded_model)) # <class 'mlflow.pyfunc.model.PyFuncModel'>
| unwrapped_model = loaded_model.unwrap_python_model()
| print(type(unwrapped_model)) # <class '__main__.MyModel'>
|
| # does not work, only predict() is exposed
| # print(loaded_model.my_custom_function(some_input))
| print(unwrapped_model.my_custom_function(some_input)) # works
| print(loaded_model.predict(some_input)) # works
|
| # works, but None is needed for context arg
| print(unwrapped_model.predict(None, some_input))
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| loader_module
| Model's flavor configuration
|
| metadata
| Model metadata.
|
| model_config
| Model's flavor configuration
|
| model_id
| The model ID of the model.
|
| Returns:
| The model ID of the model.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| input_example
| The input example provided when the model was saved.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __hash__ = None
FUNCTIONS
add_to_model(model, loader_module, data=None, code=None, conda_env=None, python_env=None, model_config=None, model_code_path=None, **kwargs)
Add a ``pyfunc`` spec to the model configuration.
Defines ``pyfunc`` configuration schema. Caller can use this to create a valid ``pyfunc`` model
flavor out of an existing directory structure. For example, other model flavors can use this to
specify how to use their output as a ``pyfunc``.
NOTE:
All paths are relative to the exported model root directory.
Args:
model: Existing model.
loader_module: The module to be used to load the model.
data: Path to the model data.
code: Path to the code dependencies.
conda_env: Conda environment.
python_env: Python environment.
model_config: The model configuration to apply to the model. This configuration
is available during model loading.
.. Note:: Experimental: This parameter may change or be removed in a future
release without warning.
model_code_path: Path to the model code.
kwargs: Additional key-value pairs to include in the ``pyfunc`` flavor specification.
Values must be YAML-serializable.
Returns:
Updated model configuration.
build_model_env(model_uri, save_path, env_manager='virtualenv')
Prebuild model python environment and generate an archive file saved to provided
`save_path`.
Typical usages:
- Pre-build a model's environment in Databricks Runtime and then download the prebuilt
python environment archive file. This pre-built environment archive can then be used
in `mlflow.pyfunc.spark_udf` for remote inference execution when using Databricks Connect
to remotely connect to a Databricks environment for code execution.
.. note::
The `build_model_env` API is intended to only work when executed within Databricks runtime,
serving the purpose of capturing the required execution environment that is needed for
remote code execution when using DBConnect. The environment archive is designed to be used
when performing remote execution using `mlflow.pyfunc.spark_udf` in
Databricks runtime or Databricks Connect client and has no other purpose.
The prebuilt env archive file cannot be used across different Databricks runtime
versions or different platform machines. As such, if you connect to a different cluster
that is running a different runtime version on Databricks, you will need to execute this
API in a notebook and retrieve the generated archive to your local machine. Each
environment snapshot is unique to the model, the runtime version of your remote
Databricks cluster, and the specification of the udf execution environment.
When using the prebuilt env in `mlflow.pyfunc.spark_udf`, MLflow will verify
whether the spark UDF sandbox environment matches the prebuilt env requirements and will
raise Exceptions if there are compatibility issues. If these occur, simply re-run this API
in the cluster that you are attempting to attach to.
.. code-block:: python
:caption: Example
from mlflow.pyfunc import build_model_env
# Create a python environment archive file at the path `prebuilt_env_uri`
prebuilt_env_uri = build_model_env(f"runs:/{run_id}/model", "/path/to/save_directory")
Args:
model_uri: URI to the model that is used to build the python environment.
save_path: The directory path that is used to save the prebuilt model environment
archive file path.
The path can be either local directory path or
mounted DBFS path such as '/dbfs/...' or
mounted UC volume path such as '/Volumes/...'.
env_manager: The environment manager to use in order to create the python environment
for model inference, the value can be either 'virtualenv' or 'uv', the default
value is 'virtualenv'.
Returns:
Return the path of an archive file containing the python environment data.
get_model_dependencies(model_uri, format='pip')
Downloads the model dependencies and returns the path to requirements.txt or conda.yaml file.
.. warning::
This API downloads all the model artifacts to the local filesystem. This may take
a long time for large models. To avoid this overhead, use
``mlflow.artifacts.download_artifacts("<model_uri>/requirements.txt")`` or
``mlflow.artifacts.download_artifacts("<model_uri>/conda.yaml")`` instead.
Args:
model_uri: The uri of the model to get dependencies from.
format: The format of the returned dependency file. If the ``"pip"`` format is
specified, the path to a pip ``requirements.txt`` file is returned.
If the ``"conda"`` format is specified, the path to a ``"conda.yaml"``
file is returned . If the ``"pip"`` format is specified but the model
was not saved with a ``requirements.txt`` file, the ``pip`` section
of the model's ``conda.yaml`` file is extracted instead, and any
additional conda dependencies are ignored. Default value is ``"pip"``.
Returns:
The local filesystem path to either a pip ``requirements.txt`` file
(if ``format="pip"``) or a ``conda.yaml`` file (if ``format="conda"``)
specifying the model's dependencies.
load_model(model_uri: str, suppress_warnings: bool = False, dst_path: str | None = None, model_config: str | pathlib.Path | dict[str, typing.Any] | None = None) -> mlflow.pyfunc.PyFuncModel
Load a model stored in Python function format.
Args:
model_uri: The location, in URI format, of the MLflow model. For example:
- ``/Users/me/path/to/local/model``
- ``relative/path/to/local/model``
- ``s3://my_bucket/path/to/model``
- ``runs:/<mlflow_run_id>/run-relative/path/to/model``
- ``models:/<model_name>/<model_version>``
- ``models:/<model_name>/<stage>``
- ``mlflow-artifacts:/path/to/model``
For more information about supported URI schemes, see
`Referencing Artifacts <https://www.mlflow.org/docs/latest/concepts.html#
artifact-locations>`_.
suppress_warnings: If ``True``, non-fatal warning messages associated with the model
loading process will be suppressed. If ``False``, these warning messages will be
emitted.
dst_path: The local filesystem path to which to download the model artifact.
This directory must already exist. If unspecified, a local output
path will be created.
model_config: The model configuration to apply to the model. The configuration will
be available as the ``model_config`` property of the ``context`` parameter
in :func:`PythonModel.load_context() <mlflow.pyfunc.PythonModel.load_context>`
and :func:`PythonModel.predict() <mlflow.pyfunc.PythonModel.predict>`.
The configuration can be passed as a file path, or a dict with string keys.
.. Note:: Experimental: This parameter may change or be removed in a future
release without warning.
load_pyfunc(model_uri, suppress_warnings=False)
.. Warning:: ``mlflow.pyfunc.load_pyfunc`` is deprecated since 1.0. This method will be removed in a future release. Use ``mlflow.pyfunc.load_model`` instead.
Load a model stored in Python function format.
Args:
model_uri: The location, in URI format, of the MLflow model. For example:
- ``/Users/me/path/to/local/model``
- ``relative/path/to/local/model``
- ``s3://my_bucket/path/to/model``
- ``runs:/<mlflow_run_id>/run-relative/path/to/model``
- ``models:/<model_name>/<model_version>``
- ``models:/<model_name>/<stage>``
- ``mlflow-artifacts:/path/to/model``
For more information about supported URI schemes, see
`Referencing Artifacts <https://www.mlflow.org/docs/latest/concepts.html#
artifact-locations>`_.
suppress_warnings: If ``True``, non-fatal warning messages associated with the model
loading process will be suppressed. If ``False``, these warning messages will be
emitted.
log_model(artifact_path=None, loader_module=None, data_path=None, code_paths=None, infer_code_paths=False, conda_env=None, python_model=None, artifacts=None, registered_model_name=None, signature: mlflow.models.signature.ModelSignature = None, input_example: Union[pandas.core.frame.DataFrame, numpy.ndarray, dict, list, ForwardRef('csr_matrix'), ForwardRef('csc_matrix'), str, bytes, tuple] = None, await_registration_for=300, pip_requirements=None, extra_pip_requirements=None, metadata=None, model_config=None, streamable=None, resources: str | list[mlflow.models.resources.Resource] | None = None, auth_policy: mlflow.models.auth_policy.AuthPolicy | None = None, uv_project_path: str | pathlib.Path | None = None, uv_groups: list[str] | None = None, uv_extras: list[str] | None = None, prompts: list[str | mlflow.entities.model_registry.prompt.Prompt] | None = None, name=None, params: dict[str, typing.Any] | None = None, tags: dict[str, typing.Any] | None = None, model_type: str | None = None, step: int = 0, model_id: str | None = None)
Log a Pyfunc model with custom inference logic and optional data dependencies as an MLflow
artifact for the current run.
For information about the workflows that this method supports, see :ref:`Workflows for
creating custom pyfunc models <pyfunc-create-custom-workflows>` and
:ref:`Which workflow is right for my use case? <pyfunc-create-custom-selecting-workflow>`.
You cannot specify the parameters for the second workflow: ``loader_module``, ``data_path``
and the parameters for the first workflow: ``python_model``, ``artifacts`` together.
Args:
artifact_path: Deprecated. Use `name` instead.
loader_module: The name of the Python module that is used to load the model
from ``data_path``. This module must define a method with the prototype
``_load_pyfunc(data_path)``. If not ``None``, this module and its
dependencies must be included in one of the following locations:
- The MLflow library.
- Package(s) listed in the model's Conda environment, specified by
the ``conda_env`` parameter.
- One or more of the files specified by the ``code_paths`` parameter.
data_path: Path to a file or directory containing model data.
code_paths: A list of local filesystem paths to Python file dependencies (or directories
containing file dependencies). These files are *prepended* to the system path when the model
is loaded. Files declared as dependencies for a given model should have relative
imports declared from a common root path if multiple files are defined with import dependencies
between them to avoid import errors when loading the model.
You can leave ``code_paths`` argument unset but set ``infer_code_paths`` to ``True`` to let MLflow
infer the model code paths. See ``infer_code_paths`` argument doc for details.
For a detailed explanation of ``code_paths`` functionality, recommended usage patterns and
limitations, see the
`code_paths usage guide <https://mlflow.org/docs/latest/model/dependencies.html?highlight=code_paths#saving-extra-code-with-an-mlflow-model>`_.
infer_code_paths: If set to ``True``, MLflow automatically infers model code paths. The inferred
code path files only include necessary python module files. Only python code files
under current working directory are automatically inferable. Default value is
``False``.
.. warning::
Please ensure that the custom python module code does not contain sensitive data such as
credential token strings, otherwise they might be included in the automatic inferred code
path files and be logged to MLflow artifact repository.
If your custom python module depends on non-python files (e.g. a JSON file) with a relative
path to the module code file path, the non-python files can't be automatically inferred as the
code path file. To address this issue, you should put all used non-python files outside
your custom code directory.
If a python code file is loaded as the python ``__main__`` module, then this code file can't be
inferred as the code path file. If your model depends on classes / functions defined in
``__main__`` module, you should use `cloudpickle` to dump your model instance in order to pickle
classes / functions in ``__main__``.
.. Note:: Experimental: This parameter may change or be removed in a future release without warning.
conda_env: Either a dictionary representation of a Conda environment or the path to a conda
environment yaml file. If provided, this describes the environment this model should be run in.
At a minimum, it should specify the dependencies contained in `get_default_conda_env()`.
If ``None``, a conda environment with pip requirements inferred by
:func:`mlflow.models.infer_pip_requirements` is added
to the model. If the requirement inference fails, it falls back to using
`get_default_pip_requirements`. pip requirements from ``conda_env`` are written to a pip
``requirements.txt`` file and the full conda environment is written to ``conda.yaml``.
The following is an *example* dictionary representation of a conda environment::
{
"name": "mlflow-env",
"channels": ["conda-forge"],
"dependencies": [
"python=3.8.15",
{
"pip": [
"scikit-learn==x.y.z"
],
},
],
}
python_model:
A file path to the PythonModel
which defines the model from code artifact,
(recommended), see https://mlflow.org/docs/latest/ml/model/models-from-code/
for details;
or an instance of a subclass of :class:`~PythonModel` or a callable object with a single
argument (see the examples below), the passed-in object is serialized using the
CloudPickle library, it requires exercising caution because these formats rely on
Python's object serialization mechanism, which can execute arbitrary code during
deserialization.
Any dependencies of the class should be included in one of the
following locations:
- The MLflow library.
- Package(s) listed in the model's Conda environment, specified by the ``conda_env``
parameter.
- One or more of the files specified by the ``code_paths`` parameter.
Note: If the class is imported from another module, as opposed to being defined in the
``__main__`` scope, the defining module should also be included in one of the listed
locations.
**Examples**
Class model
.. code-block:: python
from typing import List
import mlflow
class MyModel(mlflow.pyfunc.PythonModel):
def predict(self, context, model_input: List[str], params=None) -> List[str]:
return [i.upper() for i in model_input]
with mlflow.start_run():
model_info = mlflow.pyfunc.log_model(
name="model",
python_model=MyModel(),
)
loaded_model = mlflow.pyfunc.load_model(model_uri=model_info.model_uri)
print(loaded_model.predict(["a", "b", "c"])) # -> ["A", "B", "C"]
Functional model
.. note::
Experimental: Functional model support is experimental and may change or be removed
in a future release without warning.
.. code-block:: python
from typing import List
import mlflow
def predict(model_input: List[str]) -> List[str]:
return [i.upper() for i in model_input]
with mlflow.start_run():
model_info = mlflow.pyfunc.log_model(
name="model", python_model=predict, input_example=["a"]
)
loaded_model = mlflow.pyfunc.load_model(model_uri=model_info.model_uri)
print(loaded_model.predict(["a", "b", "c"])) # -> ["A", "B", "C"]
Model from code
.. note::
Experimental: Model from code model support is experimental and may change or
be removed in a future release without warning.
.. code-block:: python
# code.py
from typing import List
import mlflow
class MyModel(mlflow.pyfunc.PythonModel):
def predict(self, context, model_input: List[str], params=None) -> List[str]:
return [i.upper() for i in model_input]
mlflow.models.set_model(MyModel())
# log_model.py
import mlflow
with mlflow.start_run():
model_info = mlflow.pyfunc.log_model(
name="model",
python_model="code.py",
)
If the `predict` method or function has type annotations, MLflow automatically
constructs a model signature based on the type annotations (unless the ``signature``
argument is explicitly specified), and converts the input value to the specified type
before passing it to the function. Currently, the following type annotations are
supported:
- ``List[str]``
- ``List[Dict[str, str]]``
artifacts: A dictionary containing ``<name, artifact_uri>`` entries. Remote artifact URIs
are resolved to absolute filesystem paths, producing a dictionary of
``<name, absolute_path>`` entries. ``python_model`` can reference these
resolved entries as the ``artifacts`` property of the ``context`` parameter
in :func:`PythonModel.load_context() <mlflow.pyfunc.PythonModel.load_context>`
and :func:`PythonModel.predict() <mlflow.pyfunc.PythonModel.predict>`.
For example, consider the following ``artifacts`` dictionary::
{"my_file": "s3://my-bucket/path/to/my/file"}
In this case, the ``"my_file"`` artifact is downloaded from S3. The
``python_model`` can then refer to ``"my_file"`` as an absolute filesystem
path via ``context.artifacts["my_file"]``.
If ``None``, no artifacts are added to the model.
registered_model_name: If given, create a model
version under ``registered_model_name``, also creating a
registered model if one with the given name does not exist.
signature: :py:class:`ModelSignature <mlflow.models.ModelSignature>`
describes model input and output :py:class:`Schema <mlflow.types.Schema>`.
The model signature can be :py:func:`inferred <mlflow.models.infer_signature>`
from datasets with valid model input (e.g. the training dataset with target
column omitted) and valid model output (e.g. model predictions generated on
the training dataset), for example:
.. code-block:: python
from mlflow.models import infer_signature
train = df.drop_column("target_label")
predictions = ... # compute model predictions
signature = infer_signature(train, predictions)
input_example: one or several instances of valid model input. The input example is used
as a hint of what data to feed the model. It will be converted to a Pandas
DataFrame and then serialized to json using the Pandas split-oriented
format, or a numpy array where the example will be serialized to json
by converting it to a list. Bytes are base64-encoded. When the ``signature`` parameter is
``None``, the input example is used to infer a model signature.
await_registration_for: Number of seconds to wait for the model version to finish
being created and is in ``READY`` status. By default, the function
waits for five minutes. Specify 0 or None to skip waiting.
pip_requirements: Either an iterable of pip requirement strings
(e.g. ``["scikit-learn", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes the environment this model should be run in. If ``None``, a default list of requirements
is inferred by :func:`mlflow.models.infer_pip_requirements` from the current software environment.
If the requirement inference fails, it falls back to using `get_default_pip_requirements`.
Both requirements and constraints are automatically parsed and written to ``requirements.txt`` and
``constraints.txt`` files, respectively, and stored as part of the model. Requirements are also
written to the ``pip`` section of the model's conda environment (``conda.yaml``) file.
extra_pip_requirements: Either an iterable of pip
requirement strings
(e.g. ``["pandas", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes additional pip requirements that are appended to a default set of pip requirements
generated automatically based on the user's current software environment. Both requirements and
constraints are automatically parsed and written to ``requirements.txt`` and ``constraints.txt``
files, respectively, and stored as part of the model. Requirements are also written to the ``pip``
section of the model's conda environment (``conda.yaml``) file.
.. warning::
The following arguments can't be specified at the same time:
- ``conda_env``
- ``pip_requirements``
- ``extra_pip_requirements``
`This example <https://github.com/mlflow/mlflow/blob/master/examples/pip_requirements/pip_requirements.py>`_ demonstrates how to specify pip requirements using
``pip_requirements`` and ``extra_pip_requirements``.
metadata: Custom metadata dictionary passed to the model and stored in the MLmodel file.
model_config: The model configuration to apply to the model. The configuration will
be available as the ``model_config`` property of the ``context`` parameter
in :func:`PythonModel.load_context() <mlflow.pyfunc.PythonModel.load_context>`
and :func:`PythonModel.predict() <mlflow.pyfunc.PythonModel.predict>`.
The configuration can be passed as a file path, or a dict with string keys.
.. Note:: Experimental: This parameter may change or be removed in a future
release without warning.
streamable: A boolean value indicating if the model supports streaming prediction,
If None, MLflow will try to inspect if the model supports streaming
by checking if `predict_stream` method exists. Default None.
resources: A list of model resources or a resources.yaml file containing a list of
resources required to serve the model.
.. Note:: Experimental: This parameter may change or be removed in a future
release without warning.
auth_policy: Specifies the authentication policy for the model, which includes two key components.
Note that only one of `auth_policy` or `resources` should be defined.
- **System Auth Policy**: A list of resources required to serve this model.
- **User Auth Policy**: A minimal list of scopes that the user should have access to
,in order to invoke this model.
.. Note::
Experimental: This parameter may change or be removed in a future release without warning.
uv_project_path: Explicit path to the uv project directory containing uv.lock,
pyproject.toml, and optionally .python-version. This is useful for monorepos
or non-standard project layouts where the uv project is not in the current
working directory. If ``None``, MLflow will auto-detect uv.lock, pyproject.toml,
and .python-version files in the current working directory.
When a uv project is detected (either via this parameter or auto-detection),
pip requirements are generated by running ``uv export`` against the lockfile
instead of inferring dependencies by capturing imported packages during model
inference.
Auto-detection can be disabled by setting the environment variable
``MLFLOW_UV_AUTO_DETECT=false``.
.. Note:: Experimental: This parameter may change or be removed in a future
release without warning.
uv_groups: Optional list of uv dependency groups to include when exporting
requirements from the uv lockfile. Maps to ``uv export --group <name>``.
These are additive with the project's default dependencies.
.. Note:: Experimental: This parameter may change or be removed in a future
release without warning.
uv_extras: Optional list of uv extras (optional dependency sets) to include
when exporting requirements from the uv lockfile. Maps to
``uv export --extra <name>``.
.. Note:: Experimental: This parameter may change or be removed in a future
release without warning.
prompts: A list of prompt URIs registered in the MLflow Prompt Registry, to be associated with the model.
Each prompt URI should be in the form ``prompt:/<name>/<version>``. The prompts should be
registered in the MLflow Prompt Registry before being associated with the model.
This will create a mutual link between the model and the prompt. The associated prompts can be
seen in the model's metadata stored in the MLmodel file. From the Prompt Registry UI, you can
navigate to the model as well.
.. code-block:: python
import mlflow
prompt_template = "Hi, {name}! How are you doing today?"
# Register a prompt in the MLflow Prompt Registry
mlflow.prompts.register_prompt("my_prompt", prompt_template, description="A simple prompt")
# Log a model with the registered prompt
with mlflow.start_run():
model_info = mlflow.pyfunc.log_model(
name=MyModel(),
name="model",
prompts=["prompt:/my_prompt/1"]
)
print(model_info.prompts)
# Output: ['prompt:/my_prompt/1']
# Load the prompt
prompt = mlflow.genai.load_prompt(model_info.prompts[0])
name: Model name.
params: A dictionary of parameters to log with the model.
tags: A dictionary of tags to log with the model.
model_type: The type of the model.
step: The step at which to log the model outputs and metrics
model_id: The ID of the model.
Returns:
A :py:class:`ModelInfo <mlflow.models.model.ModelInfo>` instance that contains the
metadata of the logged model.
save_model(path, loader_module=None, data_path=None, code_paths=None, infer_code_paths=False, conda_env=None, mlflow_model=None, python_model=None, artifacts=None, signature: mlflow.models.signature.ModelSignature = None, input_example: Union[pandas.core.frame.DataFrame, numpy.ndarray, dict, list, ForwardRef('csr_matrix'), ForwardRef('csc_matrix'), str, bytes, tuple] = None, pip_requirements=None, extra_pip_requirements=None, metadata=None, model_config=None, streamable=None, resources: str | list[mlflow.models.resources.Resource] | None = None, auth_policy: mlflow.models.auth_policy.AuthPolicy | None = None, uv_project_path: str | pathlib.Path | None = None, uv_groups: list[str] | None = None, uv_extras: list[str] | None = None, **kwargs)
Save a Pyfunc model with custom inference logic and optional data dependencies to a path on the
local filesystem.
For information about the workflows that this method supports, please see :ref:`"workflows for
creating custom pyfunc models" <pyfunc-create-custom-workflows>` and
:ref:`"which workflow is right for my use case?" <pyfunc-create-custom-selecting-workflow>`.
Note that the parameters for the second workflow: ``loader_module``, ``data_path`` and the
parameters for the first workflow: ``python_model``, ``artifacts``, cannot be
specified together.
Args:
path: The path to which to save the Python model.
loader_module: The name of the Python module that is used to load the model
from ``data_path``. This module must define a method with the prototype
``_load_pyfunc(data_path)``. If not ``None``, this module and its
dependencies must be included in one of the following locations:
- The MLflow library.
- Package(s) listed in the model's Conda environment, specified by
the ``conda_env`` parameter.
- One or more of the files specified by the ``code_paths`` parameter.
data_path: Path to a file or directory containing model data.
code_paths: A list of local filesystem paths to Python file dependencies (or directories
containing file dependencies). These files are *prepended* to the system path when the model
is loaded. Files declared as dependencies for a given model should have relative
imports declared from a common root path if multiple files are defined with import dependencies
between them to avoid import errors when loading the model.
You can leave ``code_paths`` argument unset but set ``infer_code_paths`` to ``True`` to let MLflow
infer the model code paths. See ``infer_code_paths`` argument doc for details.
For a detailed explanation of ``code_paths`` functionality, recommended usage patterns and
limitations, see the
`code_paths usage guide <https://mlflow.org/docs/latest/model/dependencies.html?highlight=code_paths#saving-extra-code-with-an-mlflow-model>`_.
infer_code_paths: If set to ``True``, MLflow automatically infers model code paths. The inferred
code path files only include necessary python module files. Only python code files
under current working directory are automatically inferable. Default value is
``False``.
.. warning::
Please ensure that the custom python module code does not contain sensitive data such as
credential token strings, otherwise they might be included in the automatic inferred code
path files and be logged to MLflow artifact repository.
If your custom python module depends on non-python files (e.g. a JSON file) with a relative
path to the module code file path, the non-python files can't be automatically inferred as the
code path file. To address this issue, you should put all used non-python files outside
your custom code directory.
If a python code file is loaded as the python ``__main__`` module, then this code file can't be
inferred as the code path file. If your model depends on classes / functions defined in
``__main__`` module, you should use `cloudpickle` to dump your model instance in order to pickle
classes / functions in ``__main__``.
.. Note:: Experimental: This parameter may change or be removed in a future release without warning.
conda_env: Either a dictionary representation of a Conda environment or the path to a conda
environment yaml file. If provided, this describes the environment this model should be run in.
At a minimum, it should specify the dependencies contained in `get_default_conda_env()`.
If ``None``, a conda environment with pip requirements inferred by
:func:`mlflow.models.infer_pip_requirements` is added
to the model. If the requirement inference fails, it falls back to using
`get_default_pip_requirements`. pip requirements from ``conda_env`` are written to a pip
``requirements.txt`` file and the full conda environment is written to ``conda.yaml``.
The following is an *example* dictionary representation of a conda environment::
{
"name": "mlflow-env",
"channels": ["conda-forge"],
"dependencies": [
"python=3.8.15",
{
"pip": [
"scikit-learn==x.y.z"
],
},
],
}
mlflow_model: :py:mod:`mlflow.models.Model` configuration to which to add the
**python_function** flavor.
python_model:
A file path to the PythonModel
which defines the model from code artifact,
(recommended), see https://mlflow.org/docs/latest/ml/model/models-from-code/
for details;
or an instance of a subclass of :class:`~PythonModel` or a callable object with a single
argument (see the examples below), the passed-in object is serialized using the
CloudPickle library, it requires exercising caution because these formats rely on
Python's object serialization mechanism, which can execute arbitrary code during
deserialization.
Any dependencies of the class should be included in one of the
following locations:
- The MLflow library.
- Package(s) listed in the model's Conda environment, specified by the ``conda_env``
parameter.
- One or more of the files specified by the ``code_paths`` parameter.
Note: If the class is imported from another module, as opposed to being defined in the
``__main__`` scope, the defining module should also be included in one of the listed
locations.
**Examples**
Class model
.. code-block:: python
from typing import List, Dict
import mlflow
class MyModel(mlflow.pyfunc.PythonModel):
def predict(self, context, model_input: List[str], params=None) -> List[str]:
return [i.upper() for i in model_input]
mlflow.pyfunc.save_model("model", python_model=MyModel(), input_example=["a"])
model = mlflow.pyfunc.load_model("model")
print(model.predict(["a", "b", "c"])) # -> ["A", "B", "C"]
Functional model
.. note::
Experimental: Functional model support is experimental and may change or be removed
in a future release without warning.
.. code-block:: python
from typing import List
import mlflow
def predict(model_input: List[str]) -> List[str]:
return [i.upper() for i in model_input]
mlflow.pyfunc.save_model("model", python_model=predict, input_example=["a"])
model = mlflow.pyfunc.load_model("model")
print(model.predict(["a", "b", "c"])) # -> ["A", "B", "C"]
Model from code
.. note::
Experimental: Model from code model support is experimental and may change or
be removed in a future release without warning.
.. code-block:: python
# code.py
from typing import List
import mlflow
class MyModel(mlflow.pyfunc.PythonModel):
def predict(self, context, model_input: List[str], params=None) -> List[str]:
return [i.upper() for i in model_input]
mlflow.models.set_model(MyModel())
# log_model.py
import mlflow
with mlflow.start_run():
model_info = mlflow.pyfunc.log_model(
name="model",
python_model="code.py",
)
If the `predict` method or function has type annotations, MLflow automatically
constructs a model signature based on the type annotations (unless the ``signature``
argument is explicitly specified), and converts the input value to the specified type
before passing it to the function. Currently, the following type annotations are
supported:
- ``List[str]``
- ``List[Dict[str, str]]``
artifacts: A dictionary containing ``<name, artifact_uri>`` entries. Remote artifact URIs
are resolved to absolute filesystem paths, producing a dictionary of
``<name, absolute_path>`` entries. ``python_model`` can reference these
resolved entries as the ``artifacts`` property of the ``context`` parameter
in :func:`PythonModel.load_context() <mlflow.pyfunc.PythonModel.load_context>`
and :func:`PythonModel.predict() <mlflow.pyfunc.PythonModel.predict>`.
For example, consider the following ``artifacts`` dictionary::
{"my_file": "s3://my-bucket/path/to/my/file"}
In this case, the ``"my_file"`` artifact is downloaded from S3. The
``python_model`` can then refer to ``"my_file"`` as an absolute filesystem
path via ``context.artifacts["my_file"]``.
If ``None``, no artifacts are added to the model.
signature: :py:class:`ModelSignature <mlflow.models.ModelSignature>`
describes model input and output :py:class:`Schema <mlflow.types.Schema>`.
The model signature can be :py:func:`inferred <mlflow.models.infer_signature>`
from datasets with valid model input (e.g. the training dataset with target
column omitted) and valid model output (e.g. model predictions generated on
the training dataset), for example:
.. code-block:: python
from mlflow.models import infer_signature
train = df.drop_column("target_label")
predictions = ... # compute model predictions
signature = infer_signature(train, predictions)
input_example: one or several instances of valid model input. The input example is used
as a hint of what data to feed the model. It will be converted to a Pandas
DataFrame and then serialized to json using the Pandas split-oriented
format, or a numpy array where the example will be serialized to json
by converting it to a list. Bytes are base64-encoded. When the ``signature`` parameter is
``None``, the input example is used to infer a model signature.
pip_requirements: Either an iterable of pip requirement strings
(e.g. ``["scikit-learn", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes the environment this model should be run in. If ``None``, a default list of requirements
is inferred by :func:`mlflow.models.infer_pip_requirements` from the current software environment.
If the requirement inference fails, it falls back to using `get_default_pip_requirements`.
Both requirements and constraints are automatically parsed and written to ``requirements.txt`` and
``constraints.txt`` files, respectively, and stored as part of the model. Requirements are also
written to the ``pip`` section of the model's conda environment (``conda.yaml``) file.
extra_pip_requirements: Either an iterable of pip
requirement strings
(e.g. ``["pandas", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes additional pip requirements that are appended to a default set of pip requirements
generated automatically based on the user's current software environment. Both requirements and
constraints are automatically parsed and written to ``requirements.txt`` and ``constraints.txt``
files, respectively, and stored as part of the model. Requirements are also written to the ``pip``
section of the model's conda environment (``conda.yaml``) file.
.. warning::
The following arguments can't be specified at the same time:
- ``conda_env``
- ``pip_requirements``
- ``extra_pip_requirements``
`This example <https://github.com/mlflow/mlflow/blob/master/examples/pip_requirements/pip_requirements.py>`_ demonstrates how to specify pip requirements using
``pip_requirements`` and ``extra_pip_requirements``.
metadata: Custom metadata dictionary passed to the model and stored in the MLmodel file.
model_config: The model configuration to apply to the model. The configuration will
be available as the ``model_config`` property of the ``context`` parameter
in :func:`PythonModel.load_context() <mlflow.pyfunc.PythonModel.load_context>`
and :func:`PythonModel.predict() <mlflow.pyfunc.PythonModel.predict>`.
The configuration can be passed as a file path, or a dict with string keys.
.. Note:: Experimental: This parameter may change or be removed in a future
release without warning.
streamable: A boolean value indicating if the model supports streaming prediction,
If None, MLflow will try to inspect if the model supports streaming
by checking if `predict_stream` method exists. Default None.
resources: A list of model resources or a resources.yaml file containing a list of
resources required to serve the model.
.. Note:: Experimental: This parameter may change or be removed in a future
release without warning.
auth_policy: Specifies the authentication policy for the model, which includes two key components.
Note that only one of `auth_policy` or `resources` should be defined.
- **System Auth Policy**: A list of resources required to serve this model.
- **User Auth Policy**: A minimal list of scopes that the user should have access to
,in order to invoke this model.
.. Note::
Experimental: This parameter may change or be removed in a future release without warning.
uv_project_path: Explicit path to the uv project directory containing uv.lock,
pyproject.toml, and optionally .python-version. This is useful for monorepos
or non-standard project layouts where the uv project is not in the current
working directory. If ``None``, MLflow will auto-detect uv.lock, pyproject.toml,
and .python-version files in the current working directory.
When a uv project is detected (either via this parameter or auto-detection),
pip requirements are generated by running ``uv export`` against the lockfile
instead of inferring dependencies by capturing imported packages during model
inference.
Auto-detection can be disabled by setting the environment variable
``MLFLOW_UV_AUTO_DETECT=false``.
.. Note:: Experimental: This parameter may change or be removed in a future
release without warning.
uv_groups: Optional list of uv dependency groups to include when exporting
requirements from the uv lockfile. Maps to ``uv export --group <name>``.
These are additive with the project's default dependencies.
.. Note:: Experimental: This parameter may change or be removed in a future
release without warning.
uv_extras: Optional list of uv extras (optional dependency sets) to include
when exporting requirements from the uv lockfile. Maps to
``uv export --extra <name>``.
.. Note:: Experimental: This parameter may change or be removed in a future
release without warning.
kwargs: Extra keyword arguments.
spark_udf(spark, model_uri, result_type=None, env_manager=None, params: dict[str, typing.Any] | None = None, extra_env: dict[str, str] | None = None, prebuilt_env_uri: str | None = None, model_config: str | pathlib.Path | dict[str, typing.Any] | None = None)
A Spark UDF that can be used to invoke the Python function formatted model.
Parameters passed to the UDF are forwarded to the model as a DataFrame where the column names
are ordinals (0, 1, ...). On some versions of Spark (3.0 and above), it is also possible to
wrap the input in a struct. In that case, the data will be passed as a DataFrame with column
names given by the struct definition (e.g. when invoked as my_udf(struct('x', 'y')), the model
will get the data as a pandas DataFrame with 2 columns 'x' and 'y').
If a model contains a signature with tensor spec inputs, you will need to pass a column of
array type as a corresponding UDF argument. The column values of which must be one dimensional
arrays. The UDF will reshape the column values to the required shape with 'C' order
(i.e. read / write the elements using C-like index order) and cast the values as the required
tensor spec type.
If a model contains a signature, the UDF can be called without specifying column name
arguments. In this case, the UDF will be called with column names from signature, so the
evaluation dataframe's column names must match the model signature's column names.
The predictions are filtered to contain only the columns that can be represented as the
``result_type``. If the ``result_type`` is string or array of strings, all predictions are
converted to string. If the result type is not an array type, the left most column with
matching type is returned.
.. note::
Inputs of type ``pyspark.sql.types.DateType`` are not supported on earlier versions of
Spark (2.4 and below).
.. note::
When using Databricks Connect to connect to a remote Databricks cluster,
the Databricks cluster must use runtime version >= 16, and if the 'prebuilt_env_uri'
parameter is set, 'env_manager' parameter should not be set.
the Databricks cluster must use runtime version >= 15.4,and if the 'prebuilt_env_uri'
parameter is set, 'env_manager' parameter should not be set,
if the runtime version is 15.4 and the cluster is
standard access mode, the cluster need to configure
"spark.databricks.safespark.archive.artifact.unpack.disabled" to "false".
.. note::
Please be aware that when operating in Databricks Serverless,
spark tasks run within the confines of the Databricks Serverless UDF sandbox.
This environment has a total capacity limit of 1GB, combining both available
memory and local disk capacity. Furthermore, there are no GPU devices available
in this setup. Therefore, any deep-learning models that contain large weights
or require a GPU are not suitable for deployment on Databricks Serverless.
.. code-block:: python
:caption: Example
from pyspark.sql.functions import struct
predict = mlflow.pyfunc.spark_udf(spark, "/my/local/model")
df.withColumn("prediction", predict(struct("name", "age"))).show()
Args:
spark: A SparkSession object.
model_uri: The location, in URI format, of the MLflow model with the
:py:mod:`mlflow.pyfunc` flavor. For example:
- ``/Users/me/path/to/local/model``
- ``relative/path/to/local/model``
- ``s3://my_bucket/path/to/model``
- ``runs:/<mlflow_run_id>/run-relative/path/to/model``
- ``models:/<model_name>/<model_version>``
- ``models:/<model_name>/<stage>``
- ``mlflow-artifacts:/path/to/model``
For more information about supported URI schemes, see
`Referencing Artifacts <https://www.mlflow.org/docs/latest/concepts.html#
artifact-locations>`_.
result_type: the return type of the user-defined function. The value can be either a
``pyspark.sql.types.DataType`` object or a DDL-formatted type string. Only a primitive
type, an array ``pyspark.sql.types.ArrayType`` of primitive type, or a struct type
containing fields of above 2 kinds of types are allowed.
If unspecified, it tries to infer result type from model signature
output schema, if model output schema is not available, it fallbacks to use ``double``
type.
The following classes of result type are supported:
- "int" or ``pyspark.sql.types.IntegerType``: The leftmost integer that can fit in an
``int32`` or an exception if there is none.
- "long" or ``pyspark.sql.types.LongType``: The leftmost long integer that can fit in an
``int64`` or an exception if there is none.
- ``ArrayType(IntegerType|LongType)``: All integer columns that can fit into the
requested size.
- "float" or ``pyspark.sql.types.FloatType``: The leftmost numeric result cast to
``float32`` or an exception if there is none.
- "double" or ``pyspark.sql.types.DoubleType``: The leftmost numeric result cast to
``double`` or an exception if there is none.
- ``ArrayType(FloatType|DoubleType)``: All numeric columns cast to the requested type or
an exception if there are no numeric columns.
- "string" or ``pyspark.sql.types.StringType``: The leftmost column converted to
``string``.
- "boolean" or "bool" or ``pyspark.sql.types.BooleanType``: The leftmost column
converted to ``bool`` or an exception if there is none.
- ``ArrayType(StringType)``: All columns converted to ``string``.
- "field1 FIELD1_TYPE, field2 FIELD2_TYPE, ...": A struct type containing multiple
fields separated by comma, each field type must be one of types listed above.
env_manager: The environment manager to use in order to create the python environment
for model inference. Note that environment is only restored in the context
of the PySpark UDF; the software environment outside of the UDF is
unaffected. If `prebuilt_env_uri` parameter is not set, the default value
is ``local``, and the following values are supported:
- ``virtualenv``: Use virtualenv to restore the python environment that
was used to train the model. This is the default option if ``env_manager``
is not set.
- ``uv`` : Use uv to restore the python environment that
was used to train the model.
- ``conda``: Use Conda to restore the software environment
that was used to train the model.
- ``local``: Use the current Python environment for model inference, which
may differ from the environment used to train the model and may lead to
errors or invalid predictions.
If the `prebuilt_env_uri` parameter is set, `env_manager` parameter should not
be set.
params: Additional parameters to pass to the model for inference.
extra_env: Extra environment variables to pass to the UDF executors.
For overrides that need to propagate to the Spark workers (i.e.,
overriding the scoring server timeout via `MLFLOW_SCORING_SERVER_REQUEST_TIMEOUT`).
prebuilt_env_uri: The path of the prebuilt env archive file created by
`mlflow.pyfunc.build_model_env` API.
This parameter can only be used in Databricks Serverless notebook REPL,
Databricks Shared cluster notebook REPL, and Databricks Connect client
environment.
The path can be either local file path or DBFS path such as
'dbfs:/Volumes/...', in this case, MLflow automatically downloads it
to local temporary directory, "MLFLOW_MODEL_ENV_DOWNLOADING_TEMP_DIR"
environmental variable can be set to specify the temporary directory
to use.
If this parameter is set, `env_manger` parameter must not be set.
model_config: The model configuration to set when loading the model.
See 'model_config' argument in `mlflow.pyfunc.load_model` API for details.
Returns:
Spark UDF that applies the model's ``predict`` method to the data and returns a
type specified by ``result_type``, which by default is a double.
update_signature_for_type_hint_from_example(input_example: Any, signature: mlflow.models.signature.ModelSignature)
DATA
BAD_REQUEST = 4
CHAT_AGENT_INPUT_EXAMPLE = {'messages': [{'content': 'Hello!', 'role':...
CHAT_AGENT_INPUT_SCHEMA = ['messages': Array({attachments: Map(str -> ...
CHAT_AGENT_OUTPUT_SCHEMA = ['messages': Array({attachments: Map(str ->...
CHAT_MODEL_INPUT_EXAMPLE = {'max_tokens': 10, 'messages': [{'content':...
CHAT_MODEL_INPUT_SCHEMA = ['messages': Array({content: string (optiona...
CHAT_MODEL_OUTPUT_SCHEMA = ['id': string (required), 'object': string ...
CODE = 'code'
DATA = 'data'
DEFAULT_AWAIT_MAX_SLEEP_SECONDS = 300
ENV = 'env'
FLAVOR_NAME = 'python_function'
HAS_PYSPARK = False
INTERNAL_ERROR = 1
INVALID_PARAMETER_VALUE = 1000
IS_RESPONSES_AGENT_AVAILABLE = True
Iterator = typing.Iterator
A generic version of collections.abc.Iterator.
LOG_MODEL_PARAM_DOCS = ParamDocs({'name': 'Model name.', 'conda_env': ...
MAIN = 'loader_module'
MLFLOW_DISABLE_SCHEMA_DETAILS = 'MLFLOW_DISABLE_SCHEMA_DETAILS'
MLFLOW_ENFORCE_STDIN_SCORING_SERVER_FOR_SPARK_UDF = 'MLFLOW_ENFORCE_ST...
MLFLOW_MODEL_ENV_DOWNLOADING_TEMP_DIR = 'MLFLOW_MODEL_ENV_DOWNLOADING_...
MLFLOW_MODEL_IS_EXTERNAL = 'mlflow.model.isExternal'
MLFLOW_SCORING_SERVER_REQUEST_TIMEOUT = 'MLFLOW_SCORING_SERVER_REQUEST...
MLFLOW_UV_AUTO_DETECT = 'MLFLOW_UV_AUTO_DETECT'
MLMODEL_FILE_NAME = 'MLmodel'
MODEL_CODE_PATH = 'model_code_path'
MODEL_CONFIG = 'config'
ModelInputExample = typing.Union[pandas.core.frame.DataFrame, numpy......
PYTHON_VERSION = '3.12.6'
PY_VERSION = 'python_version'
PyFuncInput = typing.Union[pandas.core.frame.DataFrame, pandas... date...
PyFuncLLMOutputChunk = dict[str, typing.Any] | str
PyFuncLLMSingleInput = dict[str, typing.Any] | bool | bytes | float | ...
PyFuncOutput = pandas.core.frame.DataFrame | pandas.core.series...umpy...
RESOURCE_DOES_NOT_EXIST = 3002
TASK = 'task'
Tuple = typing.Tuple
Deprecated alias to builtins.tuple.
Tuple[X, Y] is the cross-product type of X and Y.
Example: Tuple[T1, T2] is a tuple of two elements corresponding
to type variables T1 and T2. Tuple[int, float, str] is a tuple
of an int, a float and a string.
To specify a variable-length tuple of homogeneous type, use Tuple[T, ...].
Union = typing.Union
Union type; Union[X, Y] means either X or Y.
On Python 3.10 and higher, the | operator
can also be used to denote unions;
X | Y means the same thing to the type checker as Union[X, Y].
To define a union, use e.g. Union[int, str]. Details:
- The arguments must be types and there must be at least one.
- None as an argument is a special case and is replaced by
type(None).
- Unions of unions are flattened, e.g.::
assert Union[Union[int, str], float] == Union[int, str, float]
- Unions of a single argument vanish, e.g.::
assert Union[int] == int # The constructor actually returns int
- Redundant arguments are skipped, e.g.::
assert Union[int, str, int] == Union[int, str]
- When comparing unions, the argument order is ignored, e.g.::
assert Union[int, str] == Union[str, int]
- You cannot subclass or instantiate a union.
- You can use Optional[X] as a shorthand for Union[X, None].
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\pyfunc\__init__.py
mlflow.pyspark
Python Library Documentation: package mlflow.pyspark in mlflow
NAME
mlflow.pyspark
PACKAGE CONTENTS
ml (package)
optuna (package)
DATA
__all__ = ['ml']
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\pyspark\__init__.py
mlflow.pytest
Python Library Documentation: package mlflow.pytest in mlflow
NAME
mlflow.pytest
PACKAGE CONTENTS
decorator
plugin
session
FUNCTIONS
test(fn: 'Callable[_P, _R] | None' = None) -> 'Callable[_P, _R]'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Mark a test function for the MLflow pytest plugin.
Supports both bare ``@mlflow.test`` and ``@mlflow.test()``. Raises at test
time if the plugin is not enabled, instead of silently running the test
without MLflow run/trace management.
DATA
__all__ = ['test']
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\pytest\__init__.py
mlflow.pytorch
Python Library Documentation: package mlflow.pytorch in mlflow
NAME
mlflow.pytorch
DESCRIPTION
The ``mlflow.pytorch`` module provides an API for logging and loading PyTorch models. This module
exports PyTorch models with the following flavors:
PyTorch (native) format
This is the main flavor that can be loaded back into PyTorch.
:py:mod:`mlflow.pyfunc`
Produced for use by generic pyfunc-based deployment tools and batch inference.
PACKAGE CONTENTS
_lightning_autolog
_pytorch_autolog
pickle_module
SUBMODULES
mlflow_pytorch_pickle_module
FUNCTIONS
autolog(log_every_n_epoch=1, log_every_n_step=None, log_models=True, log_datasets=True, disable=False, exclusive=False, disable_for_unsupported_versions=False, silent=False, registered_model_name=None, extra_tags=None, checkpoint=True, checkpoint_monitor='val_loss', checkpoint_mode='min', checkpoint_save_best_only=True, checkpoint_save_weights_only=False, checkpoint_save_freq='epoch', log_model_signatures=True)
.. Note:: Autologging is known to be compatible with the following package versions: ``2.4.1`` <= ``torch`` <= ``2.13.0``. Autologging may not succeed when used with package versions outside of this range.
Enables (or disables) and configures autologging from `PyTorch Lightning
<https://pytorch-lightning.readthedocs.io/en/latest>`_ to MLflow.
Autologging is performed when you call the `fit` method of
`pytorch_lightning.Trainer() <https://pytorch-lightning.readthedocs.io/en/latest/trainer.html#>`_.
Explore the complete `PyTorch MNIST <https://github.com/mlflow/mlflow/tree/master/examples/pytorch/MNIST>`_ for
an expansive example with implementation of additional lightening steps.
**Note**: Full autologging is only supported for PyTorch Lightning models,
i.e., models that subclass
`pytorch_lightning.LightningModule <https://pytorch-lightning.readthedocs.io/en/latest/lightning_module.html>`_.
Autologging support for vanilla PyTorch (ie models that only subclass
`torch.nn.Module <https://pytorch.org/docs/stable/generated/torch.nn.Module.html>`_)
only autologs calls to
`torch.utils.tensorboard.SummaryWriter <https://pytorch.org/docs/stable/tensorboard.html>`_'s
``add_scalar`` and ``add_hparams`` methods to mlflow. In this case, there's also
no notion of an "epoch".
Args:
log_every_n_epoch: If specified, logs metrics once every `n` epochs. By default, metrics
are logged after every epoch.
log_every_n_step: If specified, logs batch metrics once every `n` training step.
By default, metrics are not logged for steps. Note that setting this to 1 can cause
performance issues and is not recommended. Metrics are logged against Lightning's global
step number, and when multiple optimizers are used it is assumed that all optimizers
are stepped in each training step.
log_models: If ``True``, trained models are logged as MLflow model artifacts.
If ``False``, trained models are not logged.
log_datasets: If ``True``, dataset information is logged to MLflow Tracking.
If ``False``, dataset information is not logged.
disable: If ``True``, disables the PyTorch Lightning autologging integration.
If ``False``, enables the PyTorch Lightning autologging integration.
exclusive: If ``True``, autologged content is not logged to user-created fluent runs.
If ``False``, autologged content is logged to the active fluent run, which may be
user-created.
disable_for_unsupported_versions: If ``True``, disable autologging for versions of
pytorch and pytorch-lightning that have not been tested against this version
of the MLflow client or are incompatible.
silent: If ``True``, suppress all event logs and warnings from MLflow during PyTorch
Lightning autologging. If ``False``, show all events and warnings during PyTorch
Lightning autologging.
registered_model_name: If given, each time a model is trained, it is registered as a
new model version of the registered model with this name. The registered model is
created if it does not already exist.
extra_tags: A dictionary of extra tags to set on each managed run created by autologging.
checkpoint: Enable automatic model checkpointing, this feature only supports
pytorch-lightning >= 1.6.0.
checkpoint_monitor: In automatic model checkpointing, the metric name to monitor if
you set `model_checkpoint_save_best_only` to True.
checkpoint_mode: one of {"min", "max"}. In automatic model checkpointing,
if save_best_only=True, the decision to overwrite the current save file is made based on
either the maximization or the minimization of the monitored quantity.
checkpoint_save_best_only: If True, automatic model checkpointing only saves when
the model is considered the "best" model according to the quantity
monitored and previous checkpoint model is overwritten.
checkpoint_save_weights_only: In automatic model checkpointing, if True, then
only the model's weights will be saved. Otherwise, the optimizer states,
lr-scheduler states, etc are added in the checkpoint too.
checkpoint_save_freq: `"epoch"` or integer. When using `"epoch"`, the callback
saves the model after each epoch. When using integer, the callback
saves the model at end of this many batches. Note that if the saving isn't aligned to
epochs, the monitored metric may potentially be less reliable (it
could reflect as little as 1 batch, since the metrics get reset
every epoch). Defaults to `"epoch"`.
log_model_signatures: Whether to log model signature when `log_model` is True.
.. code-block:: python
:test:
:caption: Example
import os
import lightning as L
import torch
from torch.nn import functional as F
from torch.utils.data import DataLoader, Subset
from torchmetrics import Accuracy
from torchvision import transforms
from torchvision.datasets import MNIST
import mlflow.pytorch
from mlflow import MlflowClient
class MNISTModel(L.LightningModule):
def __init__(self):
super().__init__()
self.l1 = torch.nn.Linear(28 * 28, 10)
self.accuracy = Accuracy("multiclass", num_classes=10)
def forward(self, x):
return torch.relu(self.l1(x.view(x.size(0), -1)))
def training_step(self, batch, batch_nb):
x, y = batch
logits = self(x)
loss = F.cross_entropy(logits, y)
pred = logits.argmax(dim=1)
acc = self.accuracy(pred, y)
# PyTorch `self.log` will be automatically captured by MLflow.
self.log("train_loss", loss, on_epoch=True)
self.log("acc", acc, on_epoch=True)
return loss
def configure_optimizers(self):
return torch.optim.Adam(self.parameters(), lr=0.02)
def print_auto_logged_info(r):
tags = {k: v for k, v in r.data.tags.items() if not k.startswith("mlflow.")}
artifacts = [f.path for f in MlflowClient().list_artifacts(r.info.run_id, "model")]
print(f"run_id: {r.info.run_id}")
print(f"artifacts: {artifacts}")
print(f"params: {r.data.params}")
print(f"metrics: {r.data.metrics}")
print(f"tags: {tags}")
# Initialize our model.
mnist_model = MNISTModel()
# Load MNIST dataset.
train_ds = MNIST(
os.getcwd(), train=True, download=True, transform=transforms.ToTensor()
)
# Only take a subset of the data for faster training.
indices = torch.arange(32)
train_ds = Subset(train_ds, indices)
train_loader = DataLoader(train_ds, batch_size=8)
# Initialize a trainer.
trainer = L.Trainer(max_epochs=3)
# Auto log all MLflow entities
mlflow.pytorch.autolog()
# Train the model.
with mlflow.start_run() as run:
trainer.fit(mnist_model, train_loader)
# Fetch the auto logged parameters and metrics.
print_auto_logged_info(mlflow.get_run(run_id=run.info.run_id))
get_default_conda_env()
Returns:
The default Conda environment as a dictionary for MLflow Models produced by calls to
:func:`save_model()` and :func:`log_model()`.
.. code-block:: python
:caption: Example
import mlflow
# Log PyTorch model
with mlflow.start_run() as run:
mlflow.pytorch.log_model(model, name="model", signature=signature)
# Fetch the associated conda environment
env = mlflow.pytorch.get_default_conda_env()
print(f"conda env: {env}")
.. code-block:: text
:caption: Output
conda env {'name': 'mlflow-env',
'channels': ['conda-forge'],
'dependencies': ['python=3.8.15',
{'pip': ['torch==1.5.1',
'mlflow',
'cloudpickle==1.6.0']}]}
get_default_pip_requirements()
Returns:
A list of default pip requirements for MLflow Models produced by this flavor. Calls to
:func:`save_model()` and :func:`log_model()` produce a pip environment that, at minimum,
contains these requirements.
load_checkpoint(model_class, run_id=None, epoch=None, global_step=None, kwargs=None)
If you enable "checkpoint" in autologging, during pytorch-lightning model
training execution, checkpointed models are logged as MLflow artifacts.
Using this API, you can load the checkpointed model.
If you want to load the latest checkpoint, set both `epoch` and `global_step` to None.
If "checkpoint_save_freq" is set to "epoch" in autologging,
you can set `epoch` param to the epoch of the checkpoint to load specific epoch checkpoint.
If "checkpoint_save_freq" is set to an integer in autologging,
you can set `global_step` param to the global step of the checkpoint to load specific
global step checkpoint.
`epoch` param and `global_step` can't be set together.
Args:
model_class: The class of the training model, the class should inherit
'pytorch_lightning.LightningModule'.
run_id: The id of the run which model is logged to. If not provided,
current active run is used.
epoch: The epoch of the checkpoint to be loaded, if you set
"checkpoint_save_freq" to "epoch".
global_step: The global step of the checkpoint to be loaded, if
you set "checkpoint_save_freq" to an integer.
kwargs: Any extra kwargs needed to init the model.
Returns:
The instance of a pytorch-lightning model restored from the specified checkpoint.
.. code-block:: python
:caption: Example
import mlflow
mlflow.pytorch.autolog(checkpoint=True)
model = MyLightningModuleNet() # A custom-pytorch lightning model
train_loader = create_train_dataset_loader()
trainer = Trainer()
with mlflow.start_run() as run:
trainer.fit(model, train_loader)
run_id = run.info.run_id
# load latest checkpoint model
latest_checkpoint_model = mlflow.pytorch.load_checkpoint(MyLightningModuleNet, run_id)
# load history checkpoint model logged in second epoch
checkpoint_model = mlflow.pytorch.load_checkpoint(MyLightningModuleNet, run_id, epoch=2)
load_model(model_uri, dst_path=None, **kwargs)
Load a PyTorch model from a local file or a run.
Args:
model_uri: The location, in URI format, of the MLflow model, for example:
- ``/Users/me/path/to/local/model``
- ``relative/path/to/local/model``
- ``s3://my_bucket/path/to/model``
- ``runs:/<mlflow_run_id>/run-relative/path/to/model``
- ``models:/<model_name>/<model_version>``
- ``models:/<model_name>/<stage>``
For more information about supported URI schemes, see `Referencing Artifacts <https://www.mlflow.org/docs/latest/concepts.html#artifact-locations>`_.
dst_path: The local filesystem path to which to download the model artifact.
This directory must already exist. If unspecified, a local output path will be created.
kwargs: kwargs to pass to ``torch.load`` method.
Returns:
A PyTorch model.
.. code-block:: python
:caption: Example
import torch
import mlflow.pytorch
model = nn.Linear(1, 1)
# Log the model
with mlflow.start_run() as run:
mlflow.pytorch.log_model(model, name="model")
# Inference after loading the logged model
model_uri = f"runs:/{run.info.run_id}/model"
loaded_model = mlflow.pytorch.load_model(model_uri)
for x in [4.0, 6.0, 30.0]:
X = torch.Tensor([[x]])
y_pred = loaded_model(X)
print(f"predict X: {x}, y_pred: {y_pred.data.item():.2f}")
.. code-block:: text
:caption: Output
predict X: 4.0, y_pred: 7.57
predict X: 6.0, y_pred: 11.64
predict X: 30.0, y_pred: 60.48
log_model(pytorch_model, artifact_path: str | None = None, conda_env=None, code_paths=None, pickle_module=None, registered_model_name=None, signature: mlflow.models.signature.ModelSignature = None, input_example: Union[pandas.core.frame.DataFrame, numpy.ndarray, dict, list, ForwardRef('csr_matrix'), ForwardRef('csc_matrix'), str, bytes, tuple] = None, await_registration_for=300, extra_files=None, pip_requirements=None, extra_pip_requirements=None, metadata=None, name: str | None = None, params: dict[str, typing.Any] | None = None, tags: dict[str, typing.Any] | None = None, model_type: str | None = None, step: int = 0, model_id: str | None = None, export_model: bool = False, serialization_format: Literal['pickle', 'pt2'] = 'pt2', **kwargs)
Log a PyTorch model as an MLflow artifact for the current run.
.. warning:: Log the model with a signature to avoid inference errors.
If the model is logged without a signature, the MLflow Model Server relies on the
default inferred data type from NumPy. However, PyTorch often expects different
defaults, particularly when parsing floats. You must include the signature to ensure
that the model is logged with the correct data type so that the MLflow model server
can correctly provide valid input.
Args:
pytorch_model: PyTorch model to be saved. Can be either an eager model (subclass of
``torch.nn.Module``) or scripted model prepared via ``torch.jit.script`` or
``torch.jit.trace``.
The model accept a single ``torch.FloatTensor`` as input and produce a single output
tensor.
If saving an eager model, any code dependencies of the model's class, including the
class definition itself, should be included in one of the following locations:
- The package(s) listed in the model's Conda environment, specified by the
``conda_env`` parameter.
- One or more of the files specified by the ``code_paths`` parameter.
artifact_path: Deprecated. Use `name` instead.
conda_env: Either a dictionary representation of a Conda environment or the path to a conda
environment yaml file. If provided, this describes the environment this model should be run in.
At a minimum, it should specify the dependencies contained in `get_default_conda_env()`.
If ``None``, a conda environment with pip requirements inferred by
:func:`mlflow.models.infer_pip_requirements` is added
to the model. If the requirement inference fails, it falls back to using
`get_default_pip_requirements`. pip requirements from ``conda_env`` are written to a pip
``requirements.txt`` file and the full conda environment is written to ``conda.yaml``.
The following is an *example* dictionary representation of a conda environment::
{
"name": "mlflow-env",
"channels": ["conda-forge"],
"dependencies": [
"python=3.8.15",
{
"pip": [
"torch==x.y.z"
],
},
],
}
code_paths: A list of local filesystem paths to Python file dependencies (or directories
containing file dependencies). These files are *prepended* to the system path when the model
is loaded. Files declared as dependencies for a given model should have relative
imports declared from a common root path if multiple files are defined with import dependencies
between them to avoid import errors when loading the model.
For a detailed explanation of ``code_paths`` functionality, recommended usage patterns and
limitations, see the
`code_paths usage guide <https://mlflow.org/docs/latest/model/dependencies.html?highlight=code_paths#saving-extra-code-with-an-mlflow-model>`_.
pickle_module: The module that PyTorch should use to serialize ("pickle") the specified
``pytorch_model``. This is passed as the ``pickle_module`` parameter to
``torch.save()``. By default, this module is also used to deserialize ("unpickle") the
PyTorch model at load time.
registered_model_name: If given, create a model version under ``registered_model_name``,
also create a registered model if one with the given name does not exist.
signature: an instance of the :py:class:`ModelSignature <mlflow.models.ModelSignature>`
class that describes the model's inputs and outputs. If not specified but an
``input_example`` is supplied, a signature will be automatically inferred
based on the supplied input example and model. To disable automatic signature
inference when providing an input example, set ``signature`` to ``False``.
To manually infer a model signature, call
:py:func:`infer_signature() <mlflow.models.infer_signature>` on datasets
with valid model inputs, such as a training dataset with the target column
omitted, and valid model outputs, like model predictions made on the training
dataset, for example:
.. code-block:: python
from mlflow.models import infer_signature
train = df.drop_column("target_label")
predictions = ... # compute model predictions
signature = infer_signature(train, predictions)
input_example: one or several instances of valid model input. The input example is used
as a hint of what data to feed the model. It will be converted to a Pandas
DataFrame and then serialized to json using the Pandas split-oriented
format, or a numpy array where the example will be serialized to json
by converting it to a list. Bytes are base64-encoded. When the ``signature`` parameter is
``None``, the input example is used to infer a model signature.
await_registration_for: Number of seconds to wait for the model version to finish
being created and is in ``READY`` status. By default, the function waits for five
minutes. Specify 0 or None to skip waiting.
extra_files: A list containing the paths to corresponding extra files, if ``None``, no
extra files are added to the model. Remote URIs are resolved to absolute filesystem
paths. For example, consider the following ``extra_files`` list:
.. code-block:: python
extra_files = ["s3://my-bucket/path/to/my_file1", "/local-path/to/my_file2"]
In this case, the ``"my_file1"`` extra file is downloaded from S3.
Model paths will be ["extra_files/my_file1", "extra_files/my_file2"] in the model directory.
pip_requirements: Either an iterable of pip requirement strings
(e.g. ``["torch", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes the environment this model should be run in. If ``None``, a default list of requirements
is inferred by :func:`mlflow.models.infer_pip_requirements` from the current software environment.
If the requirement inference fails, it falls back to using `get_default_pip_requirements`.
Both requirements and constraints are automatically parsed and written to ``requirements.txt`` and
``constraints.txt`` files, respectively, and stored as part of the model. Requirements are also
written to the ``pip`` section of the model's conda environment (``conda.yaml``) file.
extra_pip_requirements: Either an iterable of pip
requirement strings
(e.g. ``["pandas", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes additional pip requirements that are appended to a default set of pip requirements
generated automatically based on the user's current software environment. Both requirements and
constraints are automatically parsed and written to ``requirements.txt`` and ``constraints.txt``
files, respectively, and stored as part of the model. Requirements are also written to the ``pip``
section of the model's conda environment (``conda.yaml``) file.
.. warning::
The following arguments can't be specified at the same time:
- ``conda_env``
- ``pip_requirements``
- ``extra_pip_requirements``
`This example <https://github.com/mlflow/mlflow/blob/master/examples/pip_requirements/pip_requirements.py>`_ demonstrates how to specify pip requirements using
``pip_requirements`` and ``extra_pip_requirements``.
metadata: Custom metadata dictionary passed to the model and stored in the MLmodel file.
name: Model name.
params: A dictionary of parameters to log with the model.
tags: A dictionary of tags to log with the model.
model_type: The type of the model.
step: The step at which to log the model outputs and metrics
model_id: The ID of the model.
export_model: If set to True, save the model as "pt2" format. This argument is deprecated.
For details, see documentation of `serialization_format` argument.
serialization_format: The serialization format used to save the PyTorch model.
Accepted values are "pickle" and "pt2".
When set to "pickle", the model is serialized using either pickle or cloudpickle,
depending on the `pickle_module` parameter.
When set to "pt2", the model is saved using torch.export.save, which exports the model
as a traced graph. This is a safer serialization format that prevents executing
arbitrary code during deserialization.
Note that "pt2" format requires `input_example` (used to trace the model graph by
virtually executing model.forward) and only supports Numpy array / Tensor or a list
of Numpy arrays / Tensors as inputs. For details, see
https://docs.pytorch.org/docs/stable/user_guide/torch_compiler/export/pt2_archive.html.
kwargs: kwargs to pass to ``torch.save`` method.
Returns:
A :py:class:`ModelInfo <mlflow.models.model.ModelInfo>` instance that contains the
metadata of the logged model.
.. code-block:: python
:caption: Example
import numpy as np
import torch
import mlflow
from mlflow import MlflowClient
from mlflow.models import infer_signature
# Define model, loss, and optimizer
model = nn.Linear(1, 1)
criterion = torch.nn.MSELoss()
optimizer = torch.optim.SGD(model.parameters(), lr=0.001)
# Create training data with relationship y = 2X
X = torch.arange(1.0, 26.0).reshape(-1, 1)
y = X * 2
# Training loop
epochs = 250
for epoch in range(epochs):
# Forward pass: Compute predicted y by passing X to the model
y_pred = model(X)
# Compute the loss
loss = criterion(y_pred, y)
# Zero gradients, perform a backward pass, and update the weights.
optimizer.zero_grad()
loss.backward()
optimizer.step()
# Create model signature
signature = infer_signature(X.numpy(), model(X).detach().numpy())
# Log the model
with mlflow.start_run() as run:
mlflow.pytorch.log_model(model, name="model", input_example=X)
# convert to scripted model and log the model
scripted_pytorch_model = torch.jit.script(model)
mlflow.pytorch.log_model(
scripted_pytorch_model, name="scripted_model", serialization_format="pickle"
)
# Fetch the logged model artifacts
print(f"run_id: {run.info.run_id}")
for artifact_path in ["model/data", "scripted_model/data"]:
artifacts = [
f.path for f in MlflowClient().list_artifacts(run.info.run_id, artifact_path)
]
print(f"artifacts: {artifacts}")
.. code-block:: text
:caption: Output
run_id: 1a1ec9e413ce48e9abf9aec20efd6f71
artifacts: ['model/data/model.pth',
'model/data/pickle_module_info.txt']
artifacts: ['scripted_model/data/model.pth',
'scripted_model/data/pickle_module_info.txt']
.. figure:: ../_static/images/pytorch_logged_models.png
PyTorch logged models
save_model(pytorch_model, path, conda_env=None, mlflow_model=None, code_paths=None, pickle_module=None, signature: mlflow.models.signature.ModelSignature = None, input_example: Union[pandas.core.frame.DataFrame, numpy.ndarray, dict, list, ForwardRef('csr_matrix'), ForwardRef('csc_matrix'), str, bytes, tuple] = None, extra_files=None, pip_requirements=None, extra_pip_requirements=None, metadata=None, export_model: bool = False, serialization_format: Literal['pickle', 'pt2'] = 'pt2', **kwargs)
Save a PyTorch model to a path on the local file system.
Args:
pytorch_model: PyTorch model to be saved. Can be either an eager model (subclass of
``torch.nn.Module``) or a scripted model prepared via ``torch.jit.script`` or
``torch.jit.trace``.
To save an eager model, any code dependencies of the model's class, including the class
definition itself, should be included in one of the following locations:
- The package(s) listed in the model's Conda environment, specified by the
``conda_env`` parameter.
- One or more of the files specified by the ``code_paths`` parameter.
path: Local path where the model is to be saved.
conda_env: Either a dictionary representation of a Conda environment or the path to a conda
environment yaml file. If provided, this describes the environment this model should be run in.
At a minimum, it should specify the dependencies contained in `get_default_conda_env()`.
If ``None``, a conda environment with pip requirements inferred by
:func:`mlflow.models.infer_pip_requirements` is added
to the model. If the requirement inference fails, it falls back to using
`get_default_pip_requirements`. pip requirements from ``conda_env`` are written to a pip
``requirements.txt`` file and the full conda environment is written to ``conda.yaml``.
The following is an *example* dictionary representation of a conda environment::
{
"name": "mlflow-env",
"channels": ["conda-forge"],
"dependencies": [
"python=3.8.15",
{
"pip": [
"torch==x.y.z"
],
},
],
}
mlflow_model: :py:mod:`mlflow.models.Model` this flavor is being added to.
code_paths: A list of local filesystem paths to Python file dependencies (or directories
containing file dependencies). These files are *prepended* to the system path when the model
is loaded. Files declared as dependencies for a given model should have relative
imports declared from a common root path if multiple files are defined with import dependencies
between them to avoid import errors when loading the model.
For a detailed explanation of ``code_paths`` functionality, recommended usage patterns and
limitations, see the
`code_paths usage guide <https://mlflow.org/docs/latest/model/dependencies.html?highlight=code_paths#saving-extra-code-with-an-mlflow-model>`_.
pickle_module: The module that PyTorch should use to serialize ("pickle") the specified
``pytorch_model``. This is passed as the ``pickle_module`` parameter to
``torch.save()``. By default, this module is also used to deserialize ("unpickle") the
model at loading time.
signature: an instance of the :py:class:`ModelSignature <mlflow.models.ModelSignature>`
class that describes the model's inputs and outputs. If not specified but an
``input_example`` is supplied, a signature will be automatically inferred
based on the supplied input example and model. To disable automatic signature
inference when providing an input example, set ``signature`` to ``False``.
To manually infer a model signature, call
:py:func:`infer_signature() <mlflow.models.infer_signature>` on datasets
with valid model inputs, such as a training dataset with the target column
omitted, and valid model outputs, like model predictions made on the training
dataset, for example:
.. code-block:: python
from mlflow.models import infer_signature
train = df.drop_column("target_label")
predictions = ... # compute model predictions
signature = infer_signature(train, predictions)
input_example: one or several instances of valid model input. The input example is used
as a hint of what data to feed the model. It will be converted to a Pandas
DataFrame and then serialized to json using the Pandas split-oriented
format, or a numpy array where the example will be serialized to json
by converting it to a list. Bytes are base64-encoded. When the ``signature`` parameter is
``None``, the input example is used to infer a model signature.
extra_files: A list containing the paths to corresponding extra files, if ``None``, no
extra files are added to the model. Remote URIs are resolved to absolute filesystem
paths. For example, consider the following ``extra_files`` list:
.. code-block:: python
extra_files = ["s3://my-bucket/path/to/my_file1", "/local-path/to/my_file2"]
In this case, the ``"my_file1"`` extra file is downloaded from S3.
Model paths will be ["extra_files/my_file1", "extra_files/my_file2"] in the model directory.
pip_requirements: Either an iterable of pip requirement strings
(e.g. ``["torch", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes the environment this model should be run in. If ``None``, a default list of requirements
is inferred by :func:`mlflow.models.infer_pip_requirements` from the current software environment.
If the requirement inference fails, it falls back to using `get_default_pip_requirements`.
Both requirements and constraints are automatically parsed and written to ``requirements.txt`` and
``constraints.txt`` files, respectively, and stored as part of the model. Requirements are also
written to the ``pip`` section of the model's conda environment (``conda.yaml``) file.
extra_pip_requirements: Either an iterable of pip
requirement strings
(e.g. ``["pandas", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes additional pip requirements that are appended to a default set of pip requirements
generated automatically based on the user's current software environment. Both requirements and
constraints are automatically parsed and written to ``requirements.txt`` and ``constraints.txt``
files, respectively, and stored as part of the model. Requirements are also written to the ``pip``
section of the model's conda environment (``conda.yaml``) file.
.. warning::
The following arguments can't be specified at the same time:
- ``conda_env``
- ``pip_requirements``
- ``extra_pip_requirements``
`This example <https://github.com/mlflow/mlflow/blob/master/examples/pip_requirements/pip_requirements.py>`_ demonstrates how to specify pip requirements using
``pip_requirements`` and ``extra_pip_requirements``.
metadata:Custom metadata dictionary passed to the model and stored in the MLmodel file.
export_model: If set to True, save the model as "pt2" format. This argument is deprecated.
For details, see documentation of `serialization_format` argument.
serialization_format: The serialization format used to save the PyTorch model.
Accepted values are "pickle" and "pt2".
When set to "pickle", the model is serialized using either pickle or cloudpickle,
depending on the `pickle_module` parameter.
When set to "pt2", the model is saved using torch.export.save, which exports the model
as a traced graph. This is a safer serialization format that prevents executing
arbitrary code during deserialization.
Note that "pt2" format requires `input_example` (used to trace the model graph by
virtually executing model.forward) and only supports Numpy array / Tensor or a list
of Numpy arrays / Tensors as inputs. For details, see
https://docs.pytorch.org/docs/stable/user_guide/torch_compiler/export/pt2_archive.html.
kwargs: kwargs to pass to ``torch.save`` method.
.. code-block:: python
:caption: Example
import os
import mlflow
import torch
model = nn.Linear(1, 1)
# Save PyTorch models to current working directory
with mlflow.start_run() as run:
mlflow.pytorch.save_model(model, "model", input_example=torch.ones(1, 1))
# Convert to a scripted model and save it
scripted_pytorch_model = torch.jit.script(model)
mlflow.pytorch.save_model(
scripted_pytorch_model, "scripted_model", serialization_format="pickle"
)
# Load each saved model for inference
for model_path in ["model", "scripted_model"]:
model_uri = f"{os.getcwd()}/{model_path}"
loaded_model = mlflow.pytorch.load_model(model_uri)
print(f"Loaded {model_path}:")
for x in [6.0, 8.0, 12.0, 30.0]:
X = torch.Tensor([[x]])
y_pred = loaded_model(X)
print(f"predict X: {x}, y_pred: {y_pred.data.item():.2f}")
print("--")
.. code-block:: text
:caption: Output
Loaded model:
predict X: 6.0, y_pred: 11.90
predict X: 8.0, y_pred: 15.92
predict X: 12.0, y_pred: 23.96
predict X: 30.0, y_pred: 60.13
--
Loaded scripted_model:
predict X: 6.0, y_pred: 11.90
predict X: 8.0, y_pred: 15.92
predict X: 12.0, y_pred: 23.96
predict X: 30.0, y_pred: 60.13
DATA
__all__ = ['autolog', 'load_model', 'save_model', 'log_model', 'get_de...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\pytorch\__init__.py
mlflow.register_model
Python Library Documentation: function register_model in module mlflow.tracking._model_registry.fluent
register_model(model_uri, name, await_registration_for=300, *, tags: dict[str, typing.Any] | None = None, env_pack: Union[Literal['databricks_model_serving'], mlflow.utils.env_pack.EnvPackConfig, NoneType] = None) -> mlflow.entities.model_registry.model_version.ModelVersion
Create a new model version in model registry for the model files specified by ``model_uri``.
Note that this method assumes the model registry backend URI is the same as that of the
tracking backend.
Args:
model_uri: URI referring to the MLmodel directory. Supported URI schemes include:
- ``runs:/`` URIs (e.g., ``runs:/<run_id>/<artifact_path>``) to register a model
from a specific run. The run ID is recorded with the model version.
- ``models:/`` URIs, which support two forms:
- ``models:/<model_name>/<version>`` to promote an existing registered
model version. The source run lineage is preserved when the
referenced model version has an associated source run.
- ``models:/<model_id>`` to create a new registered model version from a logged
model (for example, one returned by ``log_model``). The source
run lineage is preserved.
- Local filesystem paths for registering locally-persisted MLflow models that were
previously saved using ``save_model``.
name: Name of the registered model under which to create a new model version. If a
registered model with the given name does not exist, it will be created
automatically.
await_registration_for: Number of seconds to wait for the model version to finish
being created and is in ``READY`` status. By default, the function
waits for five minutes. Specify 0 or None to skip waiting.
tags: A dictionary of key-value pairs that are converted into
:py:class:`mlflow.entities.model_registry.ModelVersionTag` objects.
env_pack: Either a string or an EnvPackConfig. If specified,
the model dependencies are optionally first installed into the current Python
environment, and then the complete environment will be packaged and included
in the registered model artifacts. If the string shortcut "databricks_model_serving" is
used, then model dependencies will be installed in the current environment. This is
useful when deploying the model to a serving environment like Databricks Model Serving.
.. Note:: Experimental: This parameter may change or be removed in a future
release without warning.
Returns:
Single :py:class:`mlflow.entities.model_registry.ModelVersion` object created by
backend.
.. code-block:: python
:test:
:caption: Example
import mlflow.sklearn
from mlflow.models import infer_signature
from sklearn.datasets import make_regression
from sklearn.ensemble import RandomForestRegressor
mlflow.set_tracking_uri("sqlite:////tmp/mlruns.db")
params = {"n_estimators": 3, "random_state": 42}
X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
# Log MLflow entities
with mlflow.start_run() as run:
rfr = RandomForestRegressor(**params).fit(X, y)
signature = infer_signature(X, rfr.predict(X))
mlflow.log_params(params)
mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
model_uri = f"runs:/{run.info.run_id}/sklearn-model"
mv = mlflow.register_model(model_uri, "RandomForestRegressionModel")
print(f"Name: {mv.name}")
print(f"Version: {mv.version}")
.. code-block:: text
:caption: Output
Name: RandomForestRegressionModel
Version: 1
mlflow.register_prompt
Python Library Documentation: function register_prompt in module mlflow.tracking._model_registry.fluent
register_prompt(name: str, template: str | list[dict[str, typing.Any]], commit_message: str | None = None, tags: dict[str, str] | None = None, response_format: type[pydantic.main.BaseModel] | dict[str, typing.Any] | None = None, model_config: 'PromptModelConfig | dict[str, Any] | None' = None) -> mlflow.entities.model_registry.prompt_version.PromptVersion
Register a new :py:class:`Prompt <mlflow.entities.Prompt>` in the MLflow Prompt Registry.
A :py:class:`Prompt <mlflow.entities.Prompt>` is a pair of name and
template content at minimum. With MLflow Prompt Registry, you can create, manage, and
version control prompts with the MLflow's robust model tracking framework.
If there is no registered prompt with the given name, a new prompt will be created.
Otherwise, a new version of the existing prompt will be created.
Args:
name: The name of the prompt.
template: The template content of the prompt. Can be either:
- A string containing text with variables enclosed in double curly braces,
e.g. {{variable}}, which will be replaced with actual values by the `format` method.
- A list of dictionaries representing chat messages, where each message has
'role' and 'content' keys (e.g., [{"role": "user", "content": "Hello {{name}}"}])
.. note::
If you want to use the prompt with a framework that uses single curly braces
e.g. LangChain, you can use the `to_single_brace_format` method to convert the
loaded prompt to a format that uses single curly braces.
.. code-block:: python
prompt = client.load_prompt("my_prompt")
langchain_format = prompt.to_single_brace_format()
commit_message: A message describing the changes made to the prompt, similar to a
Git commit message. Optional.
tags: A dictionary of tags associated with the **prompt version**.
This is useful for storing version-specific information, such as the author of
the changes. Optional.
response_format: Optional Pydantic class or dictionary defining the expected response
structure. This can be used to specify the schema for structured outputs from LLM calls.
model_config: Optional PromptModelConfig instance or dictionary containing model-specific
configuration. Using PromptModelConfig provides validation and type safety.
Returns:
A :py:class:`Prompt <mlflow.entities.Prompt>` object that was created.
Example:
.. code-block:: python
import mlflow
from pydantic import BaseModel
# Register a text prompt
mlflow.register_prompt(
name="greeting_prompt",
template="Respond to the user's message as a {{style}} AI.",
response_format={"type": "string", "description": "A friendly response"},
)
# Register a chat prompt with multiple messages
mlflow.register_prompt(
name="assistant_prompt",
template=[
{"role": "system", "content": "You are a helpful {{style}} assistant."},
{"role": "user", "content": "{{question}}"},
],
response_format={"type": "object", "properties": {"answer": {"type": "string"}}},
)
# Load the prompt from the registry
prompt = mlflow.load_prompt("greeting_prompt")
# Use the prompt in your application
import openai
openai_client = openai.OpenAI()
openai_client.chat.completion.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": prompt.format(style="friendly")},
{"role": "user", "content": "Hello, how are you?"},
],
)
# Update the prompt with a new version
prompt = mlflow.register_prompt(
name="greeting_prompt",
template="Respond to the user's message as a {{style}} AI. {{greeting}}",
commit_message="Add a greeting to the prompt.",
tags={"author": "Bob"},
)
mlflow.rfunc
Python Library Documentation: package mlflow.rfunc in mlflow
NAME
mlflow.rfunc - Export and import of generic R models.
DESCRIPTION
This module defines generic filesystem format for R models and provides utilities
for saving and loading to and from this format. The format is self contained in the sense
that it includes all necessary information for anyone to load it and use it. Dependencies
are either stored directly with the model or referenced via a Conda environment.
The convention for rfunc models is to have a ``predict`` method or function with the following
signature::
predict(data: DataFrame) -> DataFrame
This convention is relied on by other MLflow components.
Rfunc model format is defined as a directory structure containing all required data, code, and
configuration:
.. code::
./dst-path/
./MLmodel: configuration
It must contain MLmodel file in its root with "r_function" format.
Example:
.. code:: shell
>tree R/mlflow/R/inst/examples/R/lm/model
├── MLmodel
└── r_model.bin
>cat R/mlflow/R/inst/examples/R/lm/model/MLmodel
time_created: 1.5337659e+09
flavors:
r_function:
version: 0.1.0
model: r_model.bin
PACKAGE CONTENTS
backend
DATA
FLAVOR_NAME = 'crate'
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\rfunc\__init__.py
mlflow.run
Python Library Documentation: function run in module mlflow.projects
run(uri, entry_point='main', version=None, parameters=None, docker_args=None, experiment_name=None, experiment_id=None, backend='local', backend_config=None, storage_dir=None, synchronous=True, run_id=None, run_name=None, env_manager=None, build_image=False, docker_auth=None)
Run an MLflow project. The project can be local or stored at a Git URI.
MLflow provides built-in support for running projects locally or remotely on a Databricks or
Kubernetes cluster. You can also run projects against other targets by installing an appropriate
third-party plugin. See `Community Plugins <../plugins.html#community-plugins>`_ for more
information.
For information on using this method in chained workflows, see `Building Multistep Workflows
<../projects.html#building-multistep-workflows>`_.
Raises:
:py:class:`mlflow.exceptions.ExecutionException` If a run launched in blocking mode
is unsuccessful.
Args:
uri: URI of project to run. A local filesystem path
or a Git repository URI (e.g. https://github.com/mlflow/mlflow-example)
pointing to a project directory containing an MLproject file.
entry_point: Entry point to run within the project. If no entry point with the specified
name is found, runs the project file ``entry_point`` as a script,
using "python" to run ``.py`` files and the default shell (specified by
environment variable ``$SHELL``) to run ``.sh`` files.
version: For Git-based projects, either a commit hash or a branch name.
parameters: Parameters (dictionary) for the entry point command.
docker_args: Arguments (dictionary) for the docker command.
experiment_name: Name of experiment under which to launch the run.
experiment_id: ID of experiment under which to launch the run.
backend: Execution backend for the run: MLflow provides built-in support for "local",
"databricks", and "kubernetes" (experimental) backends. If running against
Databricks, will run against a Databricks workspace determined as follows:
if a Databricks tracking URI of the form ``databricks://profile`` has been set
(e.g. by setting the MLFLOW_TRACKING_URI environment variable), will run
against the workspace specified by <profile>. Otherwise, runs against the
workspace specified by the default Databricks CLI profile.
backend_config: A dictionary, or a path to a JSON file (must end in '.json'), which will
be passed as config to the backend. The exact content which should be
provided is different for each execution backend and is documented
at https://www.mlflow.org/docs/latest/projects.html.
storage_dir: Used only if ``backend`` is "local". MLflow downloads artifacts from
distributed URIs passed to parameters of type ``path`` to subdirectories of
``storage_dir``.
synchronous: Whether to block while waiting for a run to complete. Defaults to True.
Note that if ``synchronous`` is False and ``backend`` is "local", this
method will return, but the current process will block when exiting until
the local run completes. If the current process is interrupted, any
asynchronous runs launched via this method will be terminated. If
``synchronous`` is True and the run fails, the current process will
error out as well.
run_id: Note: this argument is used internally by the MLflow project APIs and should
not be specified. If specified, the run ID will be used instead of
creating a new run.
run_name: The name to give the MLflow Run associated with the project execution.
If ``None``, the MLflow Run name is left unset.
env_manager: Specify an environment manager to create a new environment for the run and
install project dependencies within that environment. The following values
are supported:
- local: use the local environment
- virtualenv: use virtualenv (and pyenv for Python version management)
- uv: use uv
- conda: use conda
If unspecified, MLflow automatically determines the environment manager to
use by inspecting files in the project directory. For example, if
``python_env.yaml`` is present, virtualenv will be used.
build_image: Whether to build a new docker image of the project or to reuse an existing
image. Default: False (reuse an existing image)
docker_auth: A dictionary representing information to authenticate with a Docker
registry. See `docker.client.DockerClient.login
<https://docker-py.readthedocs.io/en/stable/client.html#docker.client.DockerClient.login>`_
for available options.
Returns:
:py:class:`mlflow.projects.SubmittedRun` exposing information (e.g. run ID)
about the launched run.
.. code-block:: python
:caption: Example
import mlflow
project_uri = "https://github.com/mlflow/mlflow-example"
params = {"alpha": 0.5, "l1_ratio": 0.01}
# Run MLflow project and create a reproducible conda environment
# on a local host
mlflow.run(project_uri, parameters=params)
.. code-block:: text
:caption: Output
...
...
Elasticnet model (alpha=0.500000, l1_ratio=0.010000):
RMSE: 0.788347345611717
MAE: 0.6155576449938276
R2: 0.19729662005412607
... mlflow.projects: === Run (ID '6a5109febe5e4a549461e149590d0a7c') succeeded ===
mlflow.search_experiments
Python Library Documentation: function search_experiments in module mlflow.tracking.fluent
search_experiments(view_type: int = 1, max_results: int | None = None, filter_string: str | None = None, order_by: list[str] | None = None) -> list[mlflow.entities.experiment.Experiment]
Search for experiments that match the specified search query.
Args:
view_type: One of enum values ``ACTIVE_ONLY``, ``DELETED_ONLY``, or ``ALL``
defined in :py:class:`mlflow.entities.ViewType`.
max_results: If passed, specifies the maximum number of experiments desired. If not
passed, all experiments will be returned.
filter_string: Filter query string (e.g., ``"name = 'my_experiment'"``), defaults to
searching for all experiments. The following identifiers, comparators, and logical
operators are supported.
Identifiers
- ``name``: Experiment name
- ``creation_time``: Experiment creation time
- ``last_update_time``: Experiment last update time
- ``tags.<tag_key>``: Experiment tag. If ``tag_key`` contains
spaces, it must be wrapped with backticks (e.g., ``"tags.`extra key`"``).
Comparators for string attributes and tags
- ``=``: Equal to
- ``!=``: Not equal to
- ``LIKE``: Case-sensitive pattern match
- ``ILIKE``: Case-insensitive pattern match
Comparators for numeric attributes
- ``=``: Equal to
- ``!=``: Not equal to
- ``<``: Less than
- ``<=``: Less than or equal to
- ``>``: Greater than
- ``>=``: Greater than or equal to
Logical operators
- ``AND``: Combines two sub-queries and returns True if both of them are True.
order_by: List of columns to order by. The ``order_by`` column can contain an optional
``DESC`` or ``ASC`` value (e.g., ``"name DESC"``). The default ordering is ``ASC``,
so ``"name"`` is equivalent to ``"name ASC"``. If unspecified, defaults to
``["last_update_time DESC"]``, which lists experiments updated most recently first.
The following fields are supported:
- ``experiment_id``: Experiment ID
- ``name``: Experiment name
- ``creation_time``: Experiment creation time
- ``last_update_time``: Experiment last update time
Returns:
A list of :py:class:`Experiment <mlflow.entities.Experiment>` objects.
.. code-block:: python
:test:
:caption: Example
import mlflow
def assert_experiment_names_equal(experiments, expected_names):
actual_names = [e.name for e in experiments if e.name != "Default"]
assert actual_names == expected_names, (actual_names, expected_names)
mlflow.set_tracking_uri("sqlite:///:memory:")
# Create experiments
for name, tags in [
("a", None),
("b", None),
("ab", {"k": "v"}),
("bb", {"k": "V"}),
]:
mlflow.create_experiment(name, tags=tags)
# Search for experiments with name "a"
experiments = mlflow.search_experiments(filter_string="name = 'a'")
assert_experiment_names_equal(experiments, ["a"])
# Search for experiments with name starting with "a"
experiments = mlflow.search_experiments(filter_string="name LIKE 'a%'")
assert_experiment_names_equal(experiments, ["ab", "a"])
# Search for experiments with tag key "k" and value ending with "v" or "V"
experiments = mlflow.search_experiments(filter_string="tags.k ILIKE '%v'")
assert_experiment_names_equal(experiments, ["bb", "ab"])
# Search for experiments with name ending with "b" and tag {"k": "v"}
experiments = mlflow.search_experiments(filter_string="name LIKE '%b' AND tags.k = 'v'")
assert_experiment_names_equal(experiments, ["ab"])
# Sort experiments by name in ascending order
experiments = mlflow.search_experiments(order_by=["name"])
assert_experiment_names_equal(experiments, ["a", "ab", "b", "bb"])
# Sort experiments by ID in descending order
experiments = mlflow.search_experiments(order_by=["experiment_id DESC"])
assert_experiment_names_equal(experiments, ["bb", "ab", "b", "a"])
mlflow.search_logged_models
Python Library Documentation: function search_logged_models in module mlflow.tracking.fluent
search_logged_models(experiment_ids: list[str] | None = None, filter_string: str | None = None, datasets: list[dict[str, str]] | None = None, max_results: int | None = None, order_by: list[dict[str, typing.Any]] | None = None, output_format: Literal['pandas', 'list'] = 'pandas') -> Union[list[mlflow.entities.logged_model.LoggedModel], ForwardRef('pandas.DataFrame')]
Search for logged models that match the specified search criteria.
Args:
experiment_ids: List of experiment IDs to search for logged models. If not specified,
the active experiment will be used.
filter_string: A SQL-like filter string to parse. The filter string syntax supports:
- Entity specification:
- attributes: `attribute_name` (default if no prefix is specified)
- metrics: `metrics.metric_name`
- parameters: `params.param_name`
- tags: `tags.tag_name`
- Comparison operators:
- For numeric entities (metrics and numeric attributes): <, <=, >, >=, =, !=
- For string entities (params, tags, string attributes): =, !=, IN, NOT IN
- Multiple conditions can be joined with 'AND'
- String values must be enclosed in single quotes
Example filter strings:
- `creation_time > 100`
- `metrics.rmse > 0.5 AND params.model_type = 'rf'`
- `tags.release IN ('v1.0', 'v1.1')`
- `params.optimizer != 'adam' AND metrics.accuracy >= 0.9`
datasets: List of dictionaries to specify datasets on which to apply metrics filters
For example, a filter string with `metrics.accuracy > 0.9` and dataset with name
"test_dataset" means we will return all logged models with accuracy > 0.9 on the
test_dataset. Metric values from ANY dataset matching the criteria are considered.
If no datasets are specified, then metrics across all datasets are considered in
the filter. The following fields are supported:
dataset_name (str):
Required. Name of the dataset.
dataset_digest (str):
Optional. Digest of the dataset.
max_results: The maximum number of logged models to return.
order_by: List of dictionaries to specify the ordering of the search results. The following
fields are supported:
field_name (str):
Required. Name of the field to order by, e.g. "metrics.accuracy".
ascending (bool):
Optional. Whether the order is ascending or not.
dataset_name (str):
Optional. If ``field_name`` refers to a metric, this field
specifies the name of the dataset associated with the metric. Only metrics
associated with the specified dataset name will be considered for ordering.
This field may only be set if ``field_name`` refers to a metric.
dataset_digest (str):
Optional. If ``field_name`` refers to a metric, this field
specifies the digest of the dataset associated with the metric. Only metrics
associated with the specified dataset name and digest will be considered for
ordering. This field may only be set if ``dataset_name`` is also set.
output_format: The output format of the search results. Supported values are 'pandas'
and 'list'.
Returns:
The search results in the specified output format.
Example:
.. code-block:: python
:test:
import mlflow
class DummyModel(mlflow.pyfunc.PythonModel):
def predict(self, context, model_input: list[str]) -> list[str]:
return model_input
model_info = mlflow.pyfunc.log_model(name="model", python_model=DummyModel())
another_model_info = mlflow.pyfunc.log_model(
name="another_model", python_model=DummyModel()
)
models = mlflow.search_logged_models(output_format="list")
assert [m.name for m in models] == ["another_model", "model"]
models = mlflow.search_logged_models(
filter_string="name = 'another_model'", output_format="list"
)
assert [m.name for m in models] == ["another_model"]
models = mlflow.search_logged_models(
order_by=[{"field_name": "creation_time", "ascending": True}], output_format="list"
)
assert [m.name for m in models] == ["model", "another_model"]
mlflow.search_model_versions
Python Library Documentation: function search_model_versions in module mlflow.tracking._model_registry.fluent
search_model_versions(max_results: int | None = None, filter_string: str | None = None, order_by: list[str] | None = None) -> list[mlflow.entities.model_registry.model_version.ModelVersion]
Search for model versions that satisfy the filter criteria.
.. warning:
The model version search results may not have aliases populated for performance reasons.
Args:
max_results: If passed, specifies the maximum number of models desired. If not
passed, all models will be returned.
filter_string: Filter query string
(e.g., ``"name = 'a_model_name' and tag.key = 'value1'"``),
defaults to searching for all model versions. The following identifiers, comparators,
and logical operators are supported.
Identifiers
- ``name``: model name.
- ``source_path``: model version source path.
- ``run_id``: The id of the mlflow run that generates the model version.
- ``tags.<tag_key>``: model version tag. If ``tag_key`` contains spaces, it must be
wrapped with backticks (e.g., ``"tags.`extra key`"``).
Comparators
- ``=``: Equal to.
- ``!=``: Not equal to.
- ``LIKE``: Case-sensitive pattern match.
- ``ILIKE``: Case-insensitive pattern match.
- ``IN``: In a value list. Only ``run_id`` identifier supports ``IN`` comparator.
Logical operators
- ``AND``: Combines two sub-queries and returns True if both of them are True.
order_by: List of column names with ASC|DESC annotation, to be used for ordering
matching search results.
Returns:
A list of :py:class:`mlflow.entities.model_registry.ModelVersion` objects
that satisfy the search expressions.
.. code-block:: python
:test:
:caption: Example
import mlflow
from sklearn.linear_model import LogisticRegression
for _ in range(2):
with mlflow.start_run():
mlflow.sklearn.log_model(
LogisticRegression(),
name="Cordoba",
registered_model_name="CordobaWeatherForecastModel",
)
# Get all versions of the model filtered by name
filter_string = "name = 'CordobaWeatherForecastModel'"
results = mlflow.search_model_versions(filter_string=filter_string)
print("-" * 80)
for res in results:
print(f"name={res.name}; run_id={res.run_id}; version={res.version}")
# Get the version of the model filtered by run_id
filter_string = "run_id = 'ae9a606a12834c04a8ef1006d0cff779'"
results = mlflow.search_model_versions(filter_string=filter_string)
print("-" * 80)
for res in results:
print(f"name={res.name}; run_id={res.run_id}; version={res.version}")
.. code-block:: text
:caption: Output
--------------------------------------------------------------------------------
name=CordobaWeatherForecastModel; run_id=ae9a606a12834c04a8ef1006d0cff779; version=2
name=CordobaWeatherForecastModel; run_id=d8f028b5fedf4faf8e458f7693dfa7ce; version=1
--------------------------------------------------------------------------------
name=CordobaWeatherForecastModel; run_id=ae9a606a12834c04a8ef1006d0cff779; version=2
mlflow.search_prompts
Python Library Documentation: function search_prompts in module mlflow.tracking._model_registry.fluent
search_prompts(filter_string: str | None = None, max_results: int | None = None) -> list[mlflow.entities.model_registry.prompt.Prompt]
Search for prompts in the MLflow Prompt Registry.
This call returns prompt metadata for prompts that have been marked
as prompts (i.e. tagged with `mlflow.prompt.is_prompt=true`). We can
further restrict results via a standard registry filter expression.
Args:
filter_string (Optional[str]):
An additional registry-search expression to apply (e.g.
`"name LIKE 'my_prompt%'"`). For Unity Catalog registries, must include
catalog and schema: "catalog = 'catalog_name' AND schema = 'schema_name'".
max_results (Optional[int]):
The maximum number of prompts to return.
Returns:
A list of :py:class:`Prompt <mlflow.entities.Prompt>` objects representing prompt metadata:
- name: The prompt name
- description: The prompt description
- tags: Prompt-level tags
- creation_timestamp: When the prompt was created
To get the actual prompt template content,
use :py:func:`mlflow.genai.load_prompt()` API with a specific version:
.. code-block:: python
import mlflow
# Search for prompts
prompts = mlflow.genai.search_prompts(filter_string="name LIKE 'greeting%'")
# Get prompts by experiment
prompts = mlflow.genai.search_prompts(filter_string='experiment_id = "1"')
# Get specific version content
for prompt in prompts:
prompt_version = mlflow.genai.load_prompt(prompt.name, version="1")
print(f"Template: {prompt_version.template}")
mlflow.search_registered_models
Python Library Documentation: function search_registered_models in module mlflow.tracking._model_registry.fluent
search_registered_models(max_results: int | None = None, filter_string: str | None = None, order_by: list[str] | None = None) -> list[mlflow.entities.model_registry.registered_model.RegisteredModel]
Search for registered models that satisfy the filter criteria.
Args:
max_results: If passed, specifies the maximum number of models desired. If not
passed, all models will be returned.
filter_string: Filter query string (e.g., "name = 'a_model_name' and tag.key = 'value1'"),
defaults to searching for all registered models. The following identifiers, comparators,
and logical operators are supported.
Identifiers
- "name": registered model name.
- "tags.<tag_key>": registered model tag. If "tag_key" contains spaces, it must be
wrapped with backticks (e.g., "tags.`extra key`").
Comparators
- "=": Equal to.
- "!=": Not equal to.
- "LIKE": Case-sensitive pattern match.
- "ILIKE": Case-insensitive pattern match.
Logical operators
- "AND": Combines two sub-queries and returns True if both of them are True.
order_by: List of column names with ASC|DESC annotation, to be used for ordering
matching search results.
Returns:
A list of :py:class:`mlflow.entities.model_registry.RegisteredModel` objects
that satisfy the search expressions.
.. code-block:: python
:test:
:caption: Example
import mlflow
from sklearn.linear_model import LogisticRegression
with mlflow.start_run():
mlflow.sklearn.log_model(
LogisticRegression(),
name="Cordoba",
registered_model_name="CordobaWeatherForecastModel",
)
mlflow.sklearn.log_model(
LogisticRegression(),
name="Boston",
registered_model_name="BostonWeatherForecastModel",
)
# Get search results filtered by the registered model name
filter_string = "name = 'CordobaWeatherForecastModel'"
results = mlflow.search_registered_models(filter_string=filter_string)
print("-" * 80)
for res in results:
for mv in res.latest_versions:
print(f"name={mv.name}; run_id={mv.run_id}; version={mv.version}")
# Get search results filtered by the registered model name that matches
# prefix pattern
filter_string = "name LIKE 'Boston%'"
results = mlflow.search_registered_models(filter_string=filter_string)
print("-" * 80)
for res in results:
for mv in res.latest_versions:
print(f"name={mv.name}; run_id={mv.run_id}; version={mv.version}")
# Get all registered models and order them by ascending order of the names
results = mlflow.search_registered_models(order_by=["name ASC"])
print("-" * 80)
for res in results:
for mv in res.latest_versions:
print(f"name={mv.name}; run_id={mv.run_id}; version={mv.version}")
.. code-block:: text
:caption: Output
--------------------------------------------------------------------------------
name=CordobaWeatherForecastModel; run_id=248c66a666744b4887bdeb2f9cf7f1c6; version=1
--------------------------------------------------------------------------------
name=BostonWeatherForecastModel; run_id=248c66a666744b4887bdeb2f9cf7f1c6; version=1
--------------------------------------------------------------------------------
name=BostonWeatherForecastModel; run_id=248c66a666744b4887bdeb2f9cf7f1c6; version=1
name=CordobaWeatherForecastModel; run_id=248c66a666744b4887bdeb2f9cf7f1c6; version=1
mlflow.search_runs
Python Library Documentation: function search_runs in module mlflow.tracking.fluent
search_runs(experiment_ids: list[str] | None = None, filter_string: str = '', run_view_type: int = 1, max_results: int = 100000, order_by: list[str] | None = None, output_format: str = 'pandas', search_all_experiments: bool = False, experiment_names: list[str] | None = None) -> Union[list[mlflow.entities.run.Run], ForwardRef('pandas.DataFrame')]
Search for Runs that fit the specified criteria.
Args:
experiment_ids: List of experiment IDs. Search can work with experiment IDs or
experiment names, but not both in the same call. Values other than
``None`` or ``[]`` will result in error if ``experiment_names`` is
also not ``None`` or ``[]``. ``None`` will default to the active
experiment if ``experiment_names`` is ``None`` or ``[]``.
filter_string: Filter query string, defaults to searching all runs.
run_view_type: one of enum values ``ACTIVE_ONLY``, ``DELETED_ONLY``, or ``ALL`` runs
defined in :py:class:`mlflow.entities.ViewType`.
max_results: The maximum number of runs to put in the dataframe. Default is 100,000
to avoid causing out-of-memory issues on the user's machine.
order_by: List of columns to order by (e.g., "metrics.rmse"). The ``order_by`` column
can contain an optional ``DESC`` or ``ASC`` value. The default is ``ASC``.
The default ordering is to sort by ``start_time DESC``, then ``run_id``.
output_format: The output format to be returned. If ``pandas``, a ``pandas.DataFrame``
is returned and, if ``list``, a list of :py:class:`mlflow.entities.Run`
is returned.
search_all_experiments: Boolean specifying whether all experiments should be searched.
Only honored if ``experiment_ids`` is ``[]`` or ``None``.
experiment_names: List of experiment names. Search can work with experiment IDs or
experiment names, but not both in the same call. Values other
than ``None`` or ``[]`` will result in error if ``experiment_ids``
is also not ``None`` or ``[]``. ``None`` will default to the active
experiment if ``experiment_ids`` is ``None`` or ``[]``.
Returns:
If output_format is ``list``: a list of :py:class:`mlflow.entities.Run`. If
output_format is ``pandas``: ``pandas.DataFrame`` of runs, where each metric,
parameter, and tag is expanded into its own column named metrics.*, params.*, or
tags.* respectively. For runs that don't have a particular metric, parameter, or tag,
the value for the corresponding column is (NumPy) ``Nan``, ``None``, or ``None``
respectively.
.. code-block:: python
:test:
:caption: Example
import mlflow
# Create an experiment and log two runs under it
experiment_name = "Social NLP Experiments"
experiment_id = mlflow.create_experiment(experiment_name)
with mlflow.start_run(experiment_id=experiment_id):
mlflow.log_metric("m", 1.55)
mlflow.set_tag("s.release", "1.1.0-RC")
with mlflow.start_run(experiment_id=experiment_id):
mlflow.log_metric("m", 2.50)
mlflow.set_tag("s.release", "1.2.0-GA")
# Search for all the runs in the experiment with the given experiment ID
df = mlflow.search_runs([experiment_id], order_by=["metrics.m DESC"])
print(df[["metrics.m", "tags.s.release", "run_id"]])
print("--")
# Search the experiment_id using a filter_string with tag
# that has a case insensitive pattern
filter_string = "tags.s.release ILIKE '%rc%'"
df = mlflow.search_runs([experiment_id], filter_string=filter_string)
print(df[["metrics.m", "tags.s.release", "run_id"]])
print("--")
# Search for all the runs in the experiment with the given experiment name
df = mlflow.search_runs(experiment_names=[experiment_name], order_by=["metrics.m DESC"])
print(df[["metrics.m", "tags.s.release", "run_id"]])
.. code-block:: text
:caption: Output
metrics.m tags.s.release run_id
0 2.50 1.2.0-GA 147eed886ab44633902cc8e19b2267e2
1 1.55 1.1.0-RC 5cc7feaf532f496f885ad7750809c4d4
--
metrics.m tags.s.release run_id
0 1.55 1.1.0-RC 5cc7feaf532f496f885ad7750809c4d4
--
metrics.m tags.s.release run_id
0 2.50 1.2.0-GA 147eed886ab44633902cc8e19b2267e2
1 1.55 1.1.0-RC 5cc7feaf532f496f885ad7750809c4d4
mlflow.search_sessions
Python Library Documentation: function search_sessions in module mlflow.tracing.fluent
search_sessions(max_results: 'int' = 100, run_id: 'str | None' = None, model_id: 'str | None' = None, include_spans: 'bool' = True, locations: 'list[str] | None' = None) -> 'list[Session]'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Return complete sessions that match the given search criteria.
A session is a collection of traces that share the same session ID, typically representing
a multi-turn conversation or a series of related interactions. This API retrieves complete
sessions by first identifying unique session IDs from traces, then fetching all traces
belonging to each session in parallel.
Args:
max_results: Maximum number of sessions to return. Default is 100.
run_id: A run id to scope the search. When a trace is created under an active run,
it will be associated with the run and you can filter on the run id to retrieve
traces.
model_id: If specified, search traces associated with the given model ID.
include_spans: If ``True``, include spans in the returned traces. Otherwise, only
the trace metadata is returned. Default is ``True``.
locations: A list of locations to search over. To search over experiments, provide
a list of experiment IDs. To search over UC tables on databricks, provide
a list of locations in the format
`<catalog_name>.<schema_name>[.<table_prefix>]`.
If not provided, the search will be performed across the current active experiment.
Returns:
A list of :py:class:`Session <mlflow.entities.Session>` objects, where each session
contains :py:class:`Trace <mlflow.entities.Trace>` objects that share the same
session ID. Sessions are ordered by the timestamp of their first trace (most recent first).
Each Session object provides convenient access via ``session.id`` and supports
iteration with ``for trace in session``.
.. code-block:: python
:caption: Basic usage - search sessions in an experiment
import mlflow
# Get all sessions from the current experiment
sessions = mlflow.search_sessions()
# Each session provides convenient access to ID and traces
for session in sessions:
print(f"Session {session.id} has {len(session)} traces")
for trace in session:
print(f" Trace: {trace.info.trace_id}")
.. code-block:: python
:caption: Use sessions with evaluation
import mlflow
# Get sessions for evaluation
sessions = mlflow.search_sessions(
locations=["experiment_id"],
max_results=50,
)
# Flatten sessions for evaluation if needed
all_traces = [trace for session in sessions for trace in session]
mlflow.genai.evaluate(data=all_traces)
mlflow.search_traces
Python Library Documentation: function search_traces in module mlflow.tracing.fluent
search_traces(experiment_ids: 'list[str] | None' = None, filter_string: 'str | None' = None, max_results: 'int | None' = None, order_by: 'list[str] | None' = None, extract_fields: 'list[str] | None' = None, run_id: 'str | None' = None, return_type: "Literal['pandas', 'list'] | None" = None, model_id: 'str | None' = None, sql_warehouse_id: 'str | None' = None, include_spans: 'bool' = True, locations: 'list[str] | None' = None, flush: 'bool' = False) -> "'pandas.DataFrame' | list[Trace]"
.. Note:: Parameter ``experiment_ids`` is deprecated. Use ``locations`` instead.
Return traces that match the given list of search expressions within the experiments.
.. note::
If expected number of search results is large, consider using the
`MlflowClient.search_traces` API directly to paginate through the results. This
function returns all results in memory and may not be suitable for large result sets.
Args:
experiment_ids: List of experiment ids to scope the search.
filter_string: A search filter string.
max_results: Maximum number of traces desired. If None, all traces matching the search
expressions will be returned.
order_by: List of order_by clauses.
extract_fields:
.. deprecated:: 3.6.0
This parameter is deprecated and will be removed in a future version.
Specify fields to extract from traces using the format
``"span_name.[inputs|outputs].field_name"`` or ``"span_name.[inputs|outputs]"``.
.. note::
This parameter is only supported when the return type is set to "pandas".
For instance, ``"predict.outputs.result"`` retrieves the output ``"result"`` field from
a span named ``"predict"``, while ``"predict.outputs"`` fetches the entire outputs
dictionary, including keys ``"result"`` and ``"explanation"``.
By default, no fields are extracted into the DataFrame columns. When multiple
fields are specified, each is extracted as its own column. If an invalid field
string is provided, the function silently returns without adding that field's column.
The supported fields are limited to ``"inputs"`` and ``"outputs"`` of spans. If the
span name or field name contains a dot it must be enclosed in backticks. For example:
.. code-block:: python
# span name contains a dot
extract_fields = ["`span.name`.inputs.field"]
# field name contains a dot
extract_fields = ["span.inputs.`field.name`"]
# span name and field name contain a dot
extract_fields = ["`span.name`.inputs.`field.name`"]
run_id: A run id to scope the search. When a trace is created under an active run,
it will be associated with the run and you can filter on the run id to retrieve the
trace. See the example below for how to filter traces by run id.
return_type: The type of the return value. The following return types are supported. If
the pandas library is installed, the default return type is "pandas". Otherwise, the
default return type is "list".
- `"pandas"`: Returns a Pandas DataFrame containing information about traces
where each row represents a single trace and each column represents a field of the
trace e.g. trace_id, spans, etc.
- `"list"`: Returns a list of :py:class:`Trace <mlflow.entities.Trace>` objects.
model_id: If specified, search traces associated with the given model ID.
sql_warehouse_id: DEPRECATED. Use the `MLFLOW_TRACING_SQL_WAREHOUSE_ID` environment
variable instead. The ID of the SQL warehouse to use for
searching traces in inference tables or UC tables. Only used in Databricks.
include_spans: If ``True``, include spans in the returned traces. Otherwise, only
the trace metadata is returned, e.g., trace ID, start time, end time, etc,
without any spans. Default to ``True``.
locations: A list of locations to search over. To search over experiments, provide
a list of experiment IDs. To search over UC tables on databricks, provide
a list of locations in the format
`<catalog_name>.<schema_name>[.<table_prefix>]`.
If not provided, the search will be performed across the current active experiment.
flush: If ``True``, flush any pending async trace writes before searching. Useful
in tests or scripts to ensure all traces are visible. Default to ``False``.
Returns:
Traces that satisfy the search expressions. Either as a list of
:py:class:`Trace <mlflow.entities.Trace>` objects or as a Pandas DataFrame,
depending on the value of the `return_type` parameter.
.. code-block:: python
:test:
:caption: Search traces with extract_fields
import mlflow
with mlflow.start_span(name="span1") as span:
span.set_inputs({"a": 1, "b": 2})
span.set_outputs({"c": 3, "d": 4})
mlflow.search_traces(
extract_fields=["span1.inputs", "span1.outputs", "span1.outputs.c"],
return_type="pandas",
)
.. code-block:: python
:test:
:caption: Search traces with extract_fields and non-dictionary span inputs and outputs
import mlflow
with mlflow.start_span(name="non_dict_span") as span:
span.set_inputs(["a", "b"])
span.set_outputs([1, 2, 3])
mlflow.search_traces(
extract_fields=["non_dict_span.inputs", "non_dict_span.outputs"],
)
.. code-block:: python
:test:
:caption: Search traces by run ID and return as a list of Trace objects
import mlflow
@mlflow.trace
def traced_func(x):
return x + 1
with mlflow.start_run() as run:
traced_func(1)
mlflow.search_traces(run_id=run.info.run_id, return_type="list")
mlflow.semantic_kernel
Error rendering doc: No module named 'semantic_kernel'
mlflow.sentence_transformers
Python Library Documentation: package mlflow.sentence_transformers in mlflow
NAME
mlflow.sentence_transformers
PACKAGE CONTENTS
DATA
DEFAULT_AWAIT_MAX_SLEEP_SECONDS = 300
EMBEDDING_MODEL_INPUT_SCHEMA = ['input': string (required)]
EMBEDDING_MODEL_OUTPUT_SCHEMA = ['object': string (required), 'data': ...
FLAVOR_NAME = 'sentence_transformers'
LOG_MODEL_PARAM_DOCS = ParamDocs({'name': 'Model name.', 'conda_env': ...
MLMODEL_FILE_NAME = 'MLmodel'
ModelInputExample = typing.Union[pandas.core.frame.DataFrame, numpy......
SENTENCE_TRANSFORMERS_DATA_PATH = 'model.sentence_transformer'
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\sentence_transformers\__init__.py
mlflow.set_active_model
Python Library Documentation: function set_active_model in module mlflow.tracking.fluent
set_active_model(*, name: str | None = None, model_id: str | None = None) -> mlflow.tracking.fluent.ActiveModel
Set the active model with the specified name or model ID, and it will be used for linking
traces that are generated during the lifecycle of the model. The return value can be used as
a context manager within a ``with`` block; otherwise, you must call ``set_active_model()``
to update active model.
Args:
name: The name of the :py:class:`mlflow.entities.LoggedModel` to set as active.
If a LoggedModel with the name does not exist, it will be created under the current
experiment. If multiple LoggedModels with the name exist, the latest one will be
set as active.
model_id: The ID of the :py:class:`mlflow.entities.LoggedModel` to set as active.
If no LoggedModel with the ID exists, an exception will be raised.
Returns:
:py:class:`mlflow.ActiveModel` object that acts as a context manager wrapping the
LoggedModel's state.
.. code-block:: python
:test:
:caption: Example
import mlflow
# Set the active model by name
mlflow.set_active_model(name="my_model")
# Set the active model by model ID
model = mlflow.create_external_model(name="test_model")
mlflow.set_active_model(model_id=model.model_id)
# Use the active model in a context manager
with mlflow.set_active_model(name="new_model"):
print(mlflow.get_active_model_id())
# Traces are automatically linked to the active model
mlflow.set_active_model(name="my_model")
@mlflow.trace
def predict(model_input):
return model_input
predict("abc")
traces = mlflow.search_traces(
model_id=mlflow.get_active_model_id(), return_type="list", flush=True
)
assert len(traces) == 1
mlflow.set_experiment
Python Library Documentation: function set_experiment in module mlflow.tracking.fluent
set_experiment(experiment_name: str | None = None, experiment_id: str | None = None, trace_location: mlflow.entities.trace_location.UnityCatalog | None = None) -> mlflow.entities.experiment.Experiment
Set the given experiment as the active experiment. The experiment must either be specified by
name via `experiment_name` or by ID via `experiment_id`. The experiment name and ID cannot
both be specified.
.. note::
If the experiment being set by name does not exist, a new experiment will be
created with the given name. After the experiment has been created, it will be set
as the active experiment. On certain platforms, such as Databricks, the experiment name
must be an absolute path, e.g. ``"/Users/<username>/my-experiment"``.
Args:
experiment_name: Case sensitive name of the experiment to be activated.
experiment_id: ID of the experiment to be activated. If an experiment with this ID
does not exist, an exception is thrown.
trace_location: Optional UC trace location used to configure the experiment-derived
tracing destination. Must be an instance of
``mlflow.entities.trace_location.UnityCatalog(...)``.
Returns:
An instance of :py:class:`mlflow.entities.Experiment` representing the new active
experiment.
.. code-block:: python
:test:
:caption: Example
import mlflow
# Set an experiment name, which must be unique and case-sensitive.
experiment = mlflow.set_experiment("Social NLP Experiments")
# Get Experiment Details
print(f"Experiment_id: {experiment.experiment_id}")
print(f"Artifact Location: {experiment.artifact_location}")
print(f"Tags: {experiment.tags}")
print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
.. code-block:: text
:caption: Output
Experiment_id: 1
Artifact Location: file:///.../mlruns/1
Tags: {}
Lifecycle_stage: active
mlflow.set_experiment_tag
Python Library Documentation: function set_experiment_tag in module mlflow.tracking.fluent
set_experiment_tag(key: str, value: Any) -> None
Set a tag on the current experiment. Value is converted to a string.
Args:
key: Tag name. This string may only contain alphanumerics, underscores (_), dashes (-),
periods (.), spaces ( ), and slashes (/). All backend stores will support keys up to
length 250, but some may support larger keys.
value: Tag value, but will be string-ified if not. All backend stores will support values
up to length 5000, but some may support larger values.
.. code-block:: python
:test:
:caption: Example
import mlflow
with mlflow.start_run():
mlflow.set_experiment_tag("release.version", "2.2.0")
mlflow.set_experiment_tags
Python Library Documentation: function set_experiment_tags in module mlflow.tracking.fluent
set_experiment_tags(tags: dict[str, typing.Any]) -> None
Set tags for the current active experiment.
Args:
tags: Dictionary containing tag names and corresponding values.
.. code-block:: python
:test:
:caption: Example
import mlflow
tags = {
"engineering": "ML Platform",
"release.candidate": "RC1",
"release.version": "2.2.0",
}
# Set a batch of tags
with mlflow.start_run():
mlflow.set_experiment_tags(tags)
mlflow.set_logged_model_tags
Python Library Documentation: function set_logged_model_tags in module mlflow.tracking.fluent
set_logged_model_tags(model_id: str, tags: dict[str, typing.Any]) -> None
Set tags on the specified logged model.
Args:
model_id: ID of the model.
tags: Tags to set on the model.
Returns:
None
Example:
.. code-block:: python
:test:
import mlflow
class DummyModel(mlflow.pyfunc.PythonModel):
def predict(self, context, model_input: list[str]) -> list[str]:
return model_input
model_info = mlflow.pyfunc.log_model(name="model", python_model=DummyModel())
mlflow.set_logged_model_tags(model_info.model_id, {"key": "value"})
model = mlflow.get_logged_model(model_info.model_id)
assert model.tags["key"] == "value"
mlflow.set_model_version_tag
Python Library Documentation: function set_model_version_tag in module mlflow.tracking._model_registry.fluent
set_model_version_tag(name: str, version: str | None = None, key: str | None = None, value: Any = None) -> None
Set a tag for the model version.
Args:
name: Registered model name.
version: Registered model version.
key: Tag key to log. key is required.
value: Tag value to log. value is required.
mlflow.set_prompt_alias
Python Library Documentation: function set_prompt_alias in module mlflow.tracking._model_registry.fluent
set_prompt_alias(name: str, alias: str, version: int) -> None
Set an alias for a :py:class:`Prompt <mlflow.entities.Prompt>` in the MLflow Prompt Registry.
Args:
name: The name of the prompt.
alias: The alias to set for the prompt.
version: The version of the prompt.
Example:
.. code-block:: python
import mlflow
# Set an alias for the prompt
mlflow.set_prompt_alias(name="my_prompt", version=1, alias="production")
# Load the prompt by alias (use "@" to specify the alias)
prompt = mlflow.load_prompt("prompts:/my_prompt@production")
# Switch the alias to a new version of the prompt
mlflow.set_prompt_alias(name="my_prompt", version=2, alias="production")
# Delete the alias
mlflow.delete_prompt_alias(name="my_prompt", alias="production")
mlflow.set_registry_uri
Python Library Documentation: function set_registry_uri in module mlflow.tracking._model_registry.utils
set_registry_uri(uri: str) -> None
Set the registry server URI. This method is especially useful if you have a registry server
that's different from the tracking server.
Args:
uri: An empty string, or a local file path, prefixed with ``file:/``. Data is stored
locally at the provided file (or ``./mlruns`` if empty). An HTTP URI like
``https://my-tracking-server:5000`` or ``http://my-oss-uc-server:8080``. A Databricks
workspace, provided as the string "databricks" or, to use a Databricks CLI
`profile <https://github.com/databricks/databricks-cli#installation>`_,
"databricks://<profileName>".
.. code-block:: python
:caption: Example
import mflow
# Set model registry uri, fetch the set uri, and compare
# it with the tracking uri. They should be different
mlflow.set_registry_uri("sqlite:////tmp/registry.db")
mr_uri = mlflow.get_registry_uri()
print(f"Current registry uri: {mr_uri}")
tracking_uri = mlflow.get_tracking_uri()
print(f"Current tracking uri: {tracking_uri}")
# They should be different
assert tracking_uri != mr_uri
.. code-block:: text
:caption: Output
Current registry uri: sqlite:////tmp/registry.db
Current tracking uri: file:///.../mlruns
mlflow.set_system_metrics_node_id
Python Library Documentation: function set_system_metrics_node_id in module mlflow.system_metrics
set_system_metrics_node_id(node_id)
Set the system metrics node id.
node_id is the identifier of the machine where the metrics are collected. This is useful in
multi-node (distributed training) setup.
mlflow.set_system_metrics_samples_before_logging
Python Library Documentation: function set_system_metrics_samples_before_logging in module mlflow.system_metrics
set_system_metrics_samples_before_logging(samples)
Set the number of samples before logging system metrics.
Every time `samples` samples have been collected, the system metrics will be logged to mlflow.
By default `samples=1`.
mlflow.set_system_metrics_sampling_interval
Python Library Documentation: function set_system_metrics_sampling_interval in module mlflow.system_metrics
set_system_metrics_sampling_interval(interval)
Set the system metrics sampling interval.
Every `interval` seconds, the system metrics will be collected. By default `interval=10`.
mlflow.set_tag
Python Library Documentation: function set_tag in module mlflow.tracking.fluent
set_tag(key: str, value: Any, synchronous: bool | None = None) -> mlflow.utils.async_logging.run_operations.RunOperations | None
Set a tag under the current run. If no run is active, this method will create a new active
run.
Args:
key: Tag name. This string may only contain alphanumerics, underscores (_), dashes (-),
periods (.), spaces ( ), and slashes (/). All backend stores will support keys up to
length 250, but some may support larger keys.
value: Tag value, but will be string-ified if not. All backend stores will support values
up to length 5000, but some may support larger values.
synchronous: *Experimental* If True, blocks until the tag is logged successfully. If False,
logs the tag asynchronously and returns a future representing the logging operation.
If None, read from environment variable `MLFLOW_ENABLE_ASYNC_LOGGING`, which
defaults to False if not set.
Returns:
When `synchronous=True`, returns None. When `synchronous=False`, returns an
:py:class:`mlflow.utils.async_logging.run_operations.RunOperations` instance that
represents future for logging operation.
.. code-block:: python
:test:
:caption: Example
import mlflow
# Set a tag.
with mlflow.start_run():
mlflow.set_tag("release.version", "2.2.0")
# Set a tag in async fashion.
with mlflow.start_run():
mlflow.set_tag("release.version", "2.2.1", synchronous=False)
mlflow.set_tags
Python Library Documentation: function set_tags in module mlflow.tracking.fluent
set_tags(tags: dict[str, typing.Any], synchronous: bool | None = None) -> mlflow.utils.async_logging.run_operations.RunOperations | None
Log a batch of tags for the current run. If no run is active, this method will create a
new active run.
Args:
tags: Dictionary of tag_name: String -> value: (String, but will be string-ified if
not)
synchronous: *Experimental* If True, blocks until tags are logged successfully. If False,
logs tags asynchronously and returns a future representing the logging operation.
If None, read from environment variable `MLFLOW_ENABLE_ASYNC_LOGGING`, which
defaults to False if not set.
Returns:
When `synchronous=True`, returns None. When `synchronous=False`, returns an
:py:class:`mlflow.utils.async_logging.run_operations.RunOperations` instance that
represents future for logging operation.
.. code-block:: python
:test:
:caption: Example
import mlflow
tags = {
"engineering": "ML Platform",
"release.candidate": "RC1",
"release.version": "2.2.0",
}
# Set a batch of tags
with mlflow.start_run():
mlflow.set_tags(tags)
# Set a batch of tags in async fashion.
with mlflow.start_run():
mlflow.set_tags(tags, synchronous=False)
mlflow.set_telemetry_client
Python Library Documentation: function set_telemetry_client in module mlflow.telemetry.client set_telemetry_client()
mlflow.set_trace_tag
Python Library Documentation: function set_trace_tag in module mlflow.tracing.fluent
set_trace_tag(trace_id: 'str', key: 'str', value: 'str')
.. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
Set a tag on the trace with the given trace ID.
The trace can be an active one or the one that has already ended and recorded in the
backend. Below is an example of setting a tag on an active trace. You can replace the
``trace_id`` parameter to set a tag on an already ended trace.
.. code-block:: python
:test:
import mlflow
with mlflow.start_span(name="span") as span:
mlflow.set_trace_tag(span.trace_id, "key", "value")
Args:
trace_id: The ID of the trace to set the tag on.
key: The string key of the tag. Must be at most 250 characters long, otherwise
it will be truncated when stored.
value: The string value of the tag. Must be at most 250 characters long, otherwise
it will be truncated when stored.
mlflow.set_tracking_uri
Python Library Documentation: function set_tracking_uri in module mlflow.tracking._tracking_service.utils
set_tracking_uri(uri: str | pathlib.Path) -> None
Set the tracking server URI. This does not affect the
currently active run (if one exists), but takes effect for successive runs.
Args:
uri:
- An empty string, or a local file path, prefixed with ``file:/``. Data is stored
locally at the provided file (or ``./mlruns`` if empty).
- An HTTP URI like ``https://my-tracking-server:5000``.
- A Databricks workspace, provided as the string "databricks" or, to use a Databricks
CLI `profile <https://github.com/databricks/databricks-cli#installation>`_,
"databricks://<profileName>".
- A :py:class:`pathlib.Path` instance
.. code-block:: python
:test:
:caption: Example
import mlflow
mlflow.set_tracking_uri("file:///tmp/my_tracking")
tracking_uri = mlflow.get_tracking_uri()
print(f"Current tracking uri: {tracking_uri}")
.. code-block:: text
:caption: Output
Current tracking uri: file:///tmp/my_tracking
mlflow.set_workspace
Python Library Documentation: function set_workspace in module mlflow.tracking._workspace.fluent
set_workspace(workspace: 'str | None') -> 'None'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Set the active workspace for subsequent MLflow operations.
mlflow.shap
Python Library Documentation: package mlflow.shap in mlflow
NAME
mlflow.shap
PACKAGE CONTENTS
DATA
DEFAULT_AWAIT_MAX_SLEEP_SECONDS = 300
FLAVOR_NAME = 'shap'
LOG_MODEL_PARAM_DOCS = ParamDocs({'name': 'Model name.', 'conda_env': ...
MLMODEL_FILE_NAME = 'MLmodel'
ModelInputExample = typing.Union[pandas.core.frame.DataFrame, numpy......
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\shap\__init__.py
mlflow.sklearn
Python Library Documentation: package mlflow.sklearn in mlflow
NAME
mlflow.sklearn
DESCRIPTION
The ``mlflow.sklearn`` module provides an API for logging and loading scikit-learn models. This
module exports scikit-learn models with the following flavors:
Python (native) `pickle <https://scikit-learn.org/stable/modules/model_persistence.html>`_ format
This is the main flavor that can be loaded back into scikit-learn.
:py:mod:`mlflow.pyfunc`
Produced for use by generic pyfunc-based deployment tools and batch inference.
NOTE: The `mlflow.pyfunc` flavor is only added for scikit-learn models that define `predict()`,
since `predict()` is required for pyfunc model inference.
PACKAGE CONTENTS
utils
FUNCTIONS
autolog(log_input_examples=False, log_model_signatures=True, log_models=True, log_datasets=True, disable=False, exclusive=False, disable_for_unsupported_versions=False, silent=False, max_tuning_runs=5, log_post_training_metrics=True, serialization_format='cloudpickle', registered_model_name=None, pos_label=None, extra_tags=None)
.. Note:: Autologging is known to be compatible with the following package versions: ``1.5.2`` <= ``scikit-learn`` <= ``1.9.0``. Autologging may not succeed when used with package versions outside of this range.
Enables (or disables) and configures autologging for scikit-learn estimators.
**When is autologging performed?**
Autologging is performed when you call:
- ``estimator.fit()``
- ``estimator.fit_predict()``
- ``estimator.fit_transform()``
**Logged information**
**Parameters**
- Parameters obtained by ``estimator.get_params(deep=True)``. Note that ``get_params``
is called with ``deep=True``. This means when you fit a meta estimator that chains
a series of estimators, the parameters of these child estimators are also logged.
**Training metrics**
- A training score obtained by ``estimator.score``. Note that the training score is
computed using parameters given to ``fit()``.
- Common metrics for classifier:
- `precision score`_
.. _precision score:
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_score.html
- `recall score`_
.. _recall score:
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.recall_score.html
- `f1 score`_
.. _f1 score:
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html
- `accuracy score`_
.. _accuracy score:
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.accuracy_score.html
If the classifier has method ``predict_proba``, we additionally log:
- `log loss`_
.. _log loss:
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.log_loss.html
- `roc auc score`_
.. _roc auc score:
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.roc_auc_score.html
- Common metrics for regressor:
- `mean squared error`_
.. _mean squared error:
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_squared_error.html
- root mean squared error
- `mean absolute error`_
.. _mean absolute error:
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_absolute_error.html
- `r2 score`_
.. _r2 score:
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.r2_score.html
.. _post training metrics:
**Post training metrics**
When users call metric APIs after model training, MLflow tries to capture the metric API
results and log them as MLflow metrics to the Run associated with the model. The following
types of scikit-learn metric APIs are supported:
- model.score
- metric APIs defined in the `sklearn.metrics` module
For post training metrics autologging, the metric key format is:
"{metric_name}[-{call_index}]_{dataset_name}"
- If the metric function is from `sklearn.metrics`, the MLflow "metric_name" is the
metric function name. If the metric function is `model.score`, then "metric_name" is
"{model_class_name}_score".
- If multiple calls are made to the same scikit-learn metric API, each subsequent call
adds a "call_index" (starting from 2) to the metric key.
- MLflow uses the prediction input dataset variable name as the "dataset_name" in the
metric key. The "prediction input dataset variable" refers to the variable which was
used as the first argument of the associated `model.predict` or `model.score` call.
Note: MLflow captures the "prediction input dataset" instance in the outermost call
frame and fetches the variable name in the outermost call frame. If the "prediction
input dataset" instance is an intermediate expression without a defined variable
name, the dataset name is set to "unknown_dataset". If multiple "prediction input
dataset" instances have the same variable name, then subsequent ones will append an
index (starting from 2) to the inspected dataset name.
**Limitations**
- MLflow can only map the original prediction result object returned by a model
prediction API (including predict / predict_proba / predict_log_proba / transform,
but excluding fit_predict / fit_transform.) to an MLflow run.
MLflow cannot find run information
for other objects derived from a given prediction result (e.g. by copying or selecting
a subset of the prediction result). scikit-learn metric APIs invoked on derived objects
do not log metrics to MLflow.
- Autologging must be enabled before scikit-learn metric APIs are imported from
`sklearn.metrics`. Metric APIs imported before autologging is enabled do not log
metrics to MLflow runs.
- If user define a scorer which is not based on metric APIs in `sklearn.metrics`, then
then post training metric autologging for the scorer is invalid.
**Tags**
- An estimator class name (e.g. "LinearRegression").
- A fully qualified estimator class name
(e.g. "sklearn.linear_model._base.LinearRegression").
**Artifacts**
- An MLflow Model with the :py:mod:`mlflow.sklearn` flavor containing a fitted estimator
(logged by :py:func:`mlflow.sklearn.log_model()`). The Model also contains the
:py:mod:`mlflow.pyfunc` flavor when the scikit-learn estimator defines `predict()`.
- For post training metrics API calls, a "metric_info.json" artifact is logged. This is a
JSON object whose keys are MLflow post training metric names
(see "Post training metrics" section for the key format) and whose values are the
corresponding metric call commands that produced the metrics, e.g.
``accuracy_score(y_true=test_iris_y, y_pred=pred_iris_y, normalize=False)``.
**How does autologging work for meta estimators?**
When a meta estimator (e.g. `Pipeline`_, `GridSearchCV`_) calls ``fit()``, it internally calls
``fit()`` on its child estimators. Autologging does NOT perform logging on these constituent
``fit()`` calls.
**Parameter search**
In addition to recording the information discussed above, autologging for parameter
search meta estimators (`GridSearchCV`_ and `RandomizedSearchCV`_) records child runs
with metrics for each set of explored parameters, as well as artifacts and parameters
for the best model (if available).
**Supported estimators**
- All estimators obtained by `sklearn.utils.all_estimators`_ (including meta estimators).
- `Pipeline`_
- Parameter search estimators (`GridSearchCV`_ and `RandomizedSearchCV`_)
.. _sklearn.utils.all_estimators:
https://scikit-learn.org/stable/modules/generated/sklearn.utils.all_estimators.html
.. _Pipeline:
https://scikit-learn.org/stable/modules/generated/sklearn.pipeline.Pipeline.html
.. _GridSearchCV:
https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.GridSearchCV.html
.. _RandomizedSearchCV:
https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.RandomizedSearchCV.html
**Example**
`See more examples <https://github.com/mlflow/mlflow/blob/master/examples/sklearn_autolog>`_
.. code-block:: python
from pprint import pprint
import numpy as np
from sklearn.linear_model import LinearRegression
import mlflow
from mlflow import MlflowClient
def fetch_logged_data(run_id):
client = MlflowClient()
data = client.get_run(run_id).data
tags = {k: v for k, v in data.tags.items() if not k.startswith("mlflow.")}
artifacts = [f.path for f in client.list_artifacts(run_id, "model")]
return data.params, data.metrics, tags, artifacts
# enable autologging
mlflow.sklearn.autolog()
# prepare training data
X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]])
y = np.dot(X, np.array([1, 2])) + 3
# train a model
model = LinearRegression()
with mlflow.start_run() as run:
model.fit(X, y)
# fetch logged data
params, metrics, tags, artifacts = fetch_logged_data(run.info.run_id)
pprint(params)
# {'copy_X': 'True',
# 'fit_intercept': 'True',
# 'n_jobs': 'None',
# 'normalize': 'False'}
pprint(metrics)
# {'training_score': 1.0,
# 'training_mean_absolute_error': 2.220446049250313e-16,
# 'training_mean_squared_error': 1.9721522630525295e-31,
# 'training_r2_score': 1.0,
# 'training_root_mean_squared_error': 4.440892098500626e-16}
pprint(tags)
# {'estimator_class': 'sklearn.linear_model._base.LinearRegression',
# 'estimator_name': 'LinearRegression'}
pprint(artifacts)
# ['model/MLmodel', 'model/conda.yaml', 'model/model.pkl']
Args:
log_input_examples: If ``True``, input examples from training datasets are collected and
logged along with scikit-learn model artifacts during training. If
``False``, input examples are not logged.
Note: Input examples are MLflow model attributes
and are only collected if ``log_models`` is also ``True``.
log_model_signatures: If ``True``,
:py:class:`ModelSignatures <mlflow.models.ModelSignature>`
describing model inputs and outputs are collected and logged along
with scikit-learn model artifacts during training. If ``False``,
signatures are not logged.
Note: Model signatures are MLflow model attributes
and are only collected if ``log_models`` is also ``True``.
log_models: If ``True``, trained models are logged as MLflow model artifacts.
If ``False``, trained models are not logged.
Input examples and model signatures, which are attributes of MLflow models,
are also omitted when ``log_models`` is ``False``.
log_datasets: If ``True``, train and validation dataset information is logged to MLflow
Tracking if applicable. If ``False``, dataset information is not logged.
disable: If ``True``, disables the scikit-learn autologging integration. If ``False``,
enables the scikit-learn autologging integration.
exclusive: If ``True``, autologged content is not logged to user-created fluent runs.
If ``False``, autologged content is logged to the active fluent run,
which may be user-created.
disable_for_unsupported_versions: If ``True``, disable autologging for versions of
scikit-learn that have not been tested against this version of the MLflow
client or are incompatible.
silent: If ``True``, suppress all event logs and warnings from MLflow during scikit-learn
autologging. If ``False``, show all events and warnings during scikit-learn
autologging.
max_tuning_runs: The maximum number of child MLflow runs created for hyperparameter
search estimators. To create child runs for the best `k` results from
the search, set `max_tuning_runs` to `k`. The default value is to track
the best 5 search parameter sets. If `max_tuning_runs=None`, then
a child run is created for each search parameter set. Note: The best k
results is based on ordering in `rank_test_score`. In the case of
multi-metric evaluation with a custom scorer, the first scorer's
`rank_test_score_<scorer_name>` will be used to select the best k
results. To change metric used for selecting best k results, change
ordering of dict passed as `scoring` parameter for estimator.
log_post_training_metrics: If ``True``, post training metrics are logged. Defaults to
``True``. See the `post training metrics`_ section for more
details.
serialization_format: The format in which to serialize the model. This should be one of
the following: "pickle", "cloudpickle" or "skops".
registered_model_name: If given, each time a model is trained, it is registered as a
new model version of the registered model with this name.
The registered model is created if it does not already exist.
pos_label: If given, used as the positive label to compute binary classification
training metrics such as precision, recall, f1, etc. This parameter should
only be set for binary classification model. If used for multi-label model,
the training metrics calculation will fail and the training metrics won't
be logged. If used for regression model, the parameter will be ignored.
extra_tags: A dictionary of extra tags to set on each managed run created by autologging.
get_default_conda_env(include_cloudpickle=False, include_skops=False)
Returns:
The default Conda environment for MLflow Models produced by calls to
:func:`save_model()` and :func:`log_model()`.
get_default_pip_requirements(include_cloudpickle=False, include_skops=False)
Returns:
A list of default pip requirements for MLflow Models produced by this flavor.
Calls to :func:`save_model()` and :func:`log_model()` produce a pip environment
that, at minimum, contains these requirements.
load_model(model_uri, dst_path=None)
Load a scikit-learn model from a local file or a run.
Args:
model_uri: The location, in URI format, of the MLflow model, for example:
- ``/Users/me/path/to/local/model``
- ``relative/path/to/local/model``
- ``s3://my_bucket/path/to/model``
- ``runs:/<mlflow_run_id>/run-relative/path/to/model``
- ``models:/<model_name>/<model_version>``
- ``models:/<model_name>/<stage>``
For more information about supported URI schemes, see
`Referencing Artifacts <https://www.mlflow.org/docs/latest/concepts.html#
artifact-locations>`_.
dst_path: The local filesystem path to which to download the model artifact.
This directory must already exist. If unspecified, a local output
path will be created.
Returns:
A scikit-learn model.
.. code-block:: python
:caption: Example
import mlflow.sklearn
sk_model = mlflow.sklearn.load_model("runs:/96771d893a5e46159d9f3b49bf9013e2/sk_models")
# use Pandas DataFrame to make predictions
pandas_df = ...
predictions = sk_model.predict(pandas_df)
log_model(sk_model, artifact_path: str | None = None, conda_env=None, code_paths=None, serialization_format='skops', registered_model_name=None, signature: mlflow.models.signature.ModelSignature = None, input_example: Union[pandas.core.frame.DataFrame, numpy.ndarray, dict, list, ForwardRef('csr_matrix'), ForwardRef('csc_matrix'), str, bytes, tuple] = None, await_registration_for=300, pip_requirements=None, extra_pip_requirements=None, pyfunc_predict_fn='predict', metadata=None, extra_files=None, params: dict[str, typing.Any] | None = None, tags: dict[str, typing.Any] | None = None, model_type: str | None = None, step: int = 0, model_id: str | None = None, name: str | None = None, skops_trusted_types: list[str] | None = None, **kwargs)
Log a scikit-learn model as an MLflow artifact for the current run. Produces an MLflow Model
containing the following flavors:
- :py:mod:`mlflow.sklearn`
- :py:mod:`mlflow.pyfunc`. NOTE: This flavor is only included for scikit-learn models
that define `predict()`, since `predict()` is required for pyfunc model inference.
Args:
sk_model: scikit-learn model to be saved.
artifact_path: Deprecated. Use `name` instead.
conda_env: Either a dictionary representation of a Conda environment or the path to a conda
environment yaml file. If provided, this describes the environment this model should be run in.
At a minimum, it should specify the dependencies contained in `get_default_conda_env()`.
If ``None``, a conda environment with pip requirements inferred by
:func:`mlflow.models.infer_pip_requirements` is added
to the model. If the requirement inference fails, it falls back to using
`get_default_pip_requirements`. pip requirements from ``conda_env`` are written to a pip
``requirements.txt`` file and the full conda environment is written to ``conda.yaml``.
The following is an *example* dictionary representation of a conda environment::
{
"name": "mlflow-env",
"channels": ["conda-forge"],
"dependencies": [
"python=3.8.15",
{
"pip": [
"scikit-learn==x.y.z"
],
},
],
}
code_paths: A list of local filesystem paths to Python file dependencies (or directories
containing file dependencies). These files are *prepended* to the system path when the model
is loaded. Files declared as dependencies for a given model should have relative
imports declared from a common root path if multiple files are defined with import dependencies
between them to avoid import errors when loading the model.
For a detailed explanation of ``code_paths`` functionality, recommended usage patterns and
limitations, see the
`code_paths usage guide <https://mlflow.org/docs/latest/model/dependencies.html?highlight=code_paths#saving-extra-code-with-an-mlflow-model>`_.
serialization_format: The format in which to serialize the model. This should be one of
the formats "skops", "cloudpickle" or "pickle".
The "skops" format guarantees safe deserialization.
The "cloudpickle" format, provides better cross-system compatibility by identifying and
packaging code dependencies with the serialized model, but requires exercising
caution because these formats rely on Python's object serialization mechanism,
which can execute arbitrary code during deserialization.
registered_model_name: If given, create a model version under
``registered_model_name``, also creating a registered model if one
with the given name does not exist.
signature: an instance of the :py:class:`ModelSignature <mlflow.models.ModelSignature>`
class that describes the model's inputs and outputs. If not specified but an
``input_example`` is supplied, a signature will be automatically inferred
based on the supplied input example and model. To disable automatic signature
inference when providing an input example, set ``signature`` to ``False``.
To manually infer a model signature, call
:py:func:`infer_signature() <mlflow.models.infer_signature>` on datasets
with valid model inputs, such as a training dataset with the target column
omitted, and valid model outputs, like model predictions made on the training
dataset, for example:
.. code-block:: python
from mlflow.models import infer_signature
train = df.drop_column("target_label")
predictions = ... # compute model predictions
signature = infer_signature(train, predictions)
input_example: one or several instances of valid model input. The input example is used
as a hint of what data to feed the model. It will be converted to a Pandas
DataFrame and then serialized to json using the Pandas split-oriented
format, or a numpy array where the example will be serialized to json
by converting it to a list. Bytes are base64-encoded. When the ``signature`` parameter is
``None``, the input example is used to infer a model signature.
await_registration_for: Number of seconds to wait for the model version to finish
being created and is in ``READY`` status. By default, the function
waits for five minutes. Specify 0 or None to skip waiting.
pip_requirements: Either an iterable of pip requirement strings
(e.g. ``["scikit-learn", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes the environment this model should be run in. If ``None``, a default list of requirements
is inferred by :func:`mlflow.models.infer_pip_requirements` from the current software environment.
If the requirement inference fails, it falls back to using `get_default_pip_requirements`.
Both requirements and constraints are automatically parsed and written to ``requirements.txt`` and
``constraints.txt`` files, respectively, and stored as part of the model. Requirements are also
written to the ``pip`` section of the model's conda environment (``conda.yaml``) file.
extra_pip_requirements: Either an iterable of pip
requirement strings
(e.g. ``["pandas", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes additional pip requirements that are appended to a default set of pip requirements
generated automatically based on the user's current software environment. Both requirements and
constraints are automatically parsed and written to ``requirements.txt`` and ``constraints.txt``
files, respectively, and stored as part of the model. Requirements are also written to the ``pip``
section of the model's conda environment (``conda.yaml``) file.
.. warning::
The following arguments can't be specified at the same time:
- ``conda_env``
- ``pip_requirements``
- ``extra_pip_requirements``
`This example <https://github.com/mlflow/mlflow/blob/master/examples/pip_requirements/pip_requirements.py>`_ demonstrates how to specify pip requirements using
``pip_requirements`` and ``extra_pip_requirements``.
pyfunc_predict_fn: The name of the prediction function to use for inference with the
pyfunc representation of the resulting MLflow Model. Current supported functions
are: ``"predict"``, ``"predict_proba"``, ``"predict_log_proba"``,
``"predict_joint_log_proba"``, and ``"score"``.
metadata: Custom metadata dictionary passed to the model and stored in the MLmodel file.
extra_files: A list containing the paths to corresponding extra files, if ``None``, no
extra files are added to the model. Remote URIs are resolved to absolute filesystem
paths. For example, consider the following ``extra_files`` list:
.. code-block:: python
extra_files = ["s3://my-bucket/path/to/my_file1", "/local-path/to/my_file2"]
In this case, the ``"my_file1"`` extra file is downloaded from S3.
Model paths will be ["extra_files/my_file1", "extra_files/my_file2"] in the model directory.
params: A dictionary of parameters to log with the model.
tags: A dictionary of tags to log with the model.
model_type: The type of the model.
step: The step at which to log the model outputs and metrics
model_id: The ID of the model.
name: Model name.
skops_trusted_types: A list of trusted types when loading model that is saved as
the ``mlflow.sklearn.SERIALIZATION_FORMAT_SKOPS`` format.
kwargs: Extra arguments to pass to :py:func:`mlflow.models.Model.log`.
Returns:
A :py:class:`ModelInfo <mlflow.models.model.ModelInfo>` instance that contains the
metadata of the logged model.
.. code-block:: python
:caption: Example
import mlflow
import mlflow.sklearn
from mlflow.models import infer_signature
from sklearn.datasets import load_iris
from sklearn import tree
with mlflow.start_run():
# load dataset and train model
iris = load_iris()
sk_model = tree.DecisionTreeClassifier()
sk_model = sk_model.fit(iris.data, iris.target)
# log model params
mlflow.log_param("criterion", sk_model.criterion)
mlflow.log_param("splitter", sk_model.splitter)
signature = infer_signature(iris.data, sk_model.predict(iris.data))
# log model
mlflow.sklearn.log_model(sk_model, name="sk_models", signature=signature)
save_model(sk_model, path, conda_env=None, code_paths=None, mlflow_model=None, serialization_format='skops', signature: mlflow.models.signature.ModelSignature = None, input_example: Union[pandas.core.frame.DataFrame, numpy.ndarray, dict, list, ForwardRef('csr_matrix'), ForwardRef('csc_matrix'), str, bytes, tuple] = None, pip_requirements=None, extra_pip_requirements=None, pyfunc_predict_fn='predict', metadata=None, skops_trusted_types=None, extra_files=None)
Save a scikit-learn model to a path on the local file system. Produces a MLflow Model
containing the following flavors:
- :py:mod:`mlflow.sklearn`
- :py:mod:`mlflow.pyfunc`. NOTE: This flavor is only included for scikit-learn models
that define `predict()`, since `predict()` is required for pyfunc model inference.
Args:
sk_model: scikit-learn model to be saved.
path: Local path where the model is to be saved.
conda_env: Either a dictionary representation of a Conda environment or the path to a conda
environment yaml file. If provided, this describes the environment this model should be run in.
At a minimum, it should specify the dependencies contained in `get_default_conda_env()`.
If ``None``, a conda environment with pip requirements inferred by
:func:`mlflow.models.infer_pip_requirements` is added
to the model. If the requirement inference fails, it falls back to using
`get_default_pip_requirements`. pip requirements from ``conda_env`` are written to a pip
``requirements.txt`` file and the full conda environment is written to ``conda.yaml``.
The following is an *example* dictionary representation of a conda environment::
{
"name": "mlflow-env",
"channels": ["conda-forge"],
"dependencies": [
"python=3.8.15",
{
"pip": [
"scikit-learn==x.y.z"
],
},
],
}
code_paths: A list of local filesystem paths to Python file dependencies (or directories
containing file dependencies). These files are *prepended* to the system path when the model
is loaded. Files declared as dependencies for a given model should have relative
imports declared from a common root path if multiple files are defined with import dependencies
between them to avoid import errors when loading the model.
For a detailed explanation of ``code_paths`` functionality, recommended usage patterns and
limitations, see the
`code_paths usage guide <https://mlflow.org/docs/latest/model/dependencies.html?highlight=code_paths#saving-extra-code-with-an-mlflow-model>`_.
mlflow_model: :py:mod:`mlflow.models.Model` this flavor is being added to.
serialization_format: The format in which to serialize the model. This should be one of
the formats "skops", "cloudpickle" or "pickle".
The "skops" format guarantees safe deserialization.
The "cloudpickle" format, provides better cross-system compatibility by identifying and
packaging code dependencies with the serialized model, but requires exercising
caution because these formats rely on Python's object serialization mechanism,
which can execute arbitrary code during deserialization.
signature: an instance of the :py:class:`ModelSignature <mlflow.models.ModelSignature>`
class that describes the model's inputs and outputs. If not specified but an
``input_example`` is supplied, a signature will be automatically inferred
based on the supplied input example and model. To disable automatic signature
inference when providing an input example, set ``signature`` to ``False``.
To manually infer a model signature, call
:py:func:`infer_signature() <mlflow.models.infer_signature>` on datasets
with valid model inputs, such as a training dataset with the target column
omitted, and valid model outputs, like model predictions made on the training
dataset, for example:
.. code-block:: python
from mlflow.models import infer_signature
train = df.drop_column("target_label")
predictions = ... # compute model predictions
signature = infer_signature(train, predictions)
input_example: one or several instances of valid model input. The input example is used
as a hint of what data to feed the model. It will be converted to a Pandas
DataFrame and then serialized to json using the Pandas split-oriented
format, or a numpy array where the example will be serialized to json
by converting it to a list. Bytes are base64-encoded. When the ``signature`` parameter is
``None``, the input example is used to infer a model signature.
pip_requirements: Either an iterable of pip requirement strings
(e.g. ``["scikit-learn", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes the environment this model should be run in. If ``None``, a default list of requirements
is inferred by :func:`mlflow.models.infer_pip_requirements` from the current software environment.
If the requirement inference fails, it falls back to using `get_default_pip_requirements`.
Both requirements and constraints are automatically parsed and written to ``requirements.txt`` and
``constraints.txt`` files, respectively, and stored as part of the model. Requirements are also
written to the ``pip`` section of the model's conda environment (``conda.yaml``) file.
extra_pip_requirements: Either an iterable of pip
requirement strings
(e.g. ``["pandas", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes additional pip requirements that are appended to a default set of pip requirements
generated automatically based on the user's current software environment. Both requirements and
constraints are automatically parsed and written to ``requirements.txt`` and ``constraints.txt``
files, respectively, and stored as part of the model. Requirements are also written to the ``pip``
section of the model's conda environment (``conda.yaml``) file.
.. warning::
The following arguments can't be specified at the same time:
- ``conda_env``
- ``pip_requirements``
- ``extra_pip_requirements``
`This example <https://github.com/mlflow/mlflow/blob/master/examples/pip_requirements/pip_requirements.py>`_ demonstrates how to specify pip requirements using
``pip_requirements`` and ``extra_pip_requirements``.
pyfunc_predict_fn: The name of the prediction function to use for inference with the
pyfunc representation of the resulting MLflow Model. Current supported functions
are: ``"predict"``, ``"predict_proba"``, ``"predict_log_proba"``,
``"predict_joint_log_proba"``, and ``"score"``.
metadata: Custom metadata dictionary passed to the model and stored in the MLmodel file.
skops_trusted_types: A list of trusted types when loading model that is saved as
the ``mlflow.sklearn.SERIALIZATION_FORMAT_SKOPS`` format.
extra_files: A list containing the paths to corresponding extra files, if ``None``, no
extra files are added to the model. Remote URIs are resolved to absolute filesystem
paths. For example, consider the following ``extra_files`` list:
.. code-block:: python
extra_files = ["s3://my-bucket/path/to/my_file1", "/local-path/to/my_file2"]
In this case, the ``"my_file1"`` extra file is downloaded from S3.
Model paths will be ["extra_files/my_file1", "extra_files/my_file2"] in the model directory.
.. code-block:: python
:caption: Example
import mlflow.sklearn
from sklearn.datasets import load_iris
from sklearn import tree
iris = load_iris()
sk_model = tree.DecisionTreeClassifier()
sk_model = sk_model.fit(iris.data, iris.target)
# Save the model in cloudpickle format
# set path to location for persistence
sk_path_dir_1 = ...
mlflow.sklearn.save_model(
sk_model,
sk_path_dir_1,
serialization_format=mlflow.sklearn.SERIALIZATION_FORMAT_CLOUDPICKLE,
)
# save the model in pickle format
# set path to location for persistence
sk_path_dir_2 = ...
mlflow.sklearn.save_model(
sk_model,
sk_path_dir_2,
serialization_format=mlflow.sklearn.SERIALIZATION_FORMAT_PICKLE,
)
DATA
DEFAULT_AWAIT_MAX_SLEEP_SECONDS = 300
FLAVOR_NAME = 'sklearn'
INPUT_EXAMPLE_SAMPLE_ROWS = 5
INTERNAL_ERROR = 1
INVALID_PARAMETER_VALUE = 1000
LOG_MODEL_PARAM_DOCS = ParamDocs({'name': 'Model name.', 'conda_env': ...
MLFLOW_ALLOW_PICKLE_DESERIALIZATION = 'MLFLOW_ALLOW_PICKLE_DESERIALIZA...
MLFLOW_AUTOLOGGING = 'mlflow.autologging'
MLFLOW_DATASET_CONTEXT = 'mlflow.data.context'
MLMODEL_FILE_NAME = 'MLmodel'
ModelInputExample = typing.Union[pandas.core.frame.DataFrame, numpy......
SERIALIZATION_FORMAT_CLOUDPICKLE = 'cloudpickle'
SERIALIZATION_FORMAT_PICKLE = 'pickle'
SERIALIZATION_FORMAT_SKOPS = 'skops'
SUPPORTED_SERIALIZATION_FORMATS = ['skops', 'pickle', 'cloudpickle']
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\sklearn\__init__.py
mlflow.smolagents
Python Library Documentation: package mlflow.smolagents in mlflow
NAME
mlflow.smolagents - The ``mlflow.smolagents`` module provides an API for tracing Smolagents AI agents.
PACKAGE CONTENTS
autolog
chat
DATA
FLAVOR_NAME = 'smolagents'
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\smolagents\__init__.py
mlflow.spacy
Python Library Documentation: package mlflow.spacy in mlflow
NAME
mlflow.spacy
DESCRIPTION
The ``mlflow.spacy`` module provides an API for logging and loading spaCy models.
This module exports spacy models with the following flavors:
spaCy (native) format
This is the main flavor that can be loaded back into spaCy.
:py:mod:`mlflow.pyfunc`
Produced for use by generic pyfunc-based deployment tools and batch inference, this
flavor is created only if spaCy's model pipeline has at least one
`TextCategorizer <https://spacy.io/api/textcategorizer>`_.
PACKAGE CONTENTS
DATA
FLAVOR_NAME = 'spacy'
LOG_MODEL_PARAM_DOCS = ParamDocs({'name': 'Model name.', 'conda_env': ...
MLMODEL_FILE_NAME = 'MLmodel'
ModelInputExample = typing.Union[pandas.core.frame.DataFrame, numpy......
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\spacy\__init__.py
mlflow.spark
Python Library Documentation: package mlflow.spark in mlflow
NAME
mlflow.spark
DESCRIPTION
The ``mlflow.spark`` module provides an API for logging and loading Spark MLlib models. This module
exports Spark MLlib models with the following flavors:
Spark MLlib (native) format
Allows models to be loaded as Spark Transformers for scoring in a Spark session.
Models with this flavor can be loaded as PySpark PipelineModel objects in Python.
This is the main flavor and is always produced.
:py:mod:`mlflow.pyfunc`
Supports deployment outside of Spark by instantiating a SparkContext and reading
input data as a Spark DataFrame prior to scoring. Also supports deployment in Spark
as a Spark UDF. Models with this flavor can be loaded as Python functions
for performing inference. This flavor is always produced.
PACKAGE CONTENTS
autologging
FUNCTIONS
autolog(disable=False, silent=False)
.. Note:: Autologging is known to be compatible with the following package versions: ``3.3.0`` <= ``pyspark`` <= ``4.2.0``. Autologging may not succeed when used with package versions outside of this range.
Enables (or disables) and configures logging of Spark datasource paths, versions
(if applicable), and formats when they are read. This method is not threadsafe and assumes a
`SparkSession
<https://spark.apache.org/docs/latest/api/python/reference/pyspark.sql/api/pyspark.sql.SparkSession.html>`_
already exists with the
`mlflow-spark JAR
<https://www.mlflow.org/docs/latest/tracking.html#spark>`_
attached. It should be called on the Spark driver, not on the executors (i.e. do not call
this method within a function parallelized by Spark).
The mlflow-spark JAR used must match the Scala version of Spark. Please see the
`Maven Repository
<https://mvnrepository.com/artifact/org.mlflow/mlflow-spark>`_
for available versions. This API requires Spark 3.0 or above.
Datasource information is cached in memory and logged to all subsequent MLflow runs,
including the active MLflow run (if one exists when the data is read). Note that autologging of
Spark ML (MLlib) models is not currently supported via this API. Datasource autologging is
best-effort, meaning that if Spark is under heavy load or MLflow logging fails for any reason
(e.g., if the MLflow server is unavailable), logging may be dropped.
For any unexpected issues with autologging, check Spark driver and executor logs in addition
to stderr & stdout generated from your MLflow code - datasource information is pulled from
Spark, so logs relevant to debugging may show up amongst the Spark logs.
.. Note:: Spark datasource autologging only supports logging to MLflow runs in a single thread
.. code-block:: python
:caption: Example
import mlflow.spark
import os
import shutil
from pyspark.sql import SparkSession
# Create and persist some dummy data
# Note: the 2.12 in 'org.mlflow:mlflow-spark_2.12:2.16.2' below indicates the Scala
# version, please match this with that of Spark. The 2.16.2 indicates the mlflow version.
# Note: On environments like Databricks with pre-created SparkSessions,
# ensure the org.mlflow:mlflow-spark_2.12:2.16.2 is attached as a library to
# your cluster
spark = (
SparkSession.builder
.config(
"spark.jars.packages",
"org.mlflow:mlflow-spark_2.12:2.16.2",
)
.master("local[*]")
.getOrCreate()
)
df = spark.createDataFrame(
[(4, "spark i j k"), (5, "l m n"), (6, "spark hadoop spark"), (7, "apache hadoop")],
["id", "text"],
)
import tempfile
tempdir = tempfile.mkdtemp()
df.write.csv(os.path.join(tempdir, "my-data-path"), header=True)
# Enable Spark datasource autologging.
mlflow.spark.autolog()
loaded_df = spark.read.csv(
os.path.join(tempdir, "my-data-path"), header=True, inferSchema=True
)
# Call toPandas() to trigger a read of the Spark datasource. Datasource info
# (path and format) is logged to the current active run, or the
# next-created MLflow run if no run is currently active
with mlflow.start_run() as active_run:
pandas_df = loaded_df.toPandas()
Args:
disable: If ``True``, disables the Spark datasource autologging integration.
If ``False``, enables the Spark datasource autologging integration.
silent: If ``True``, suppress all event logs and warnings from MLflow during Spark
datasource autologging. If ``False``, show all events and warnings during Spark
datasource autologging.
get_default_conda_env(is_spark_connect_model=False)
Returns:
The default Conda environment for MLflow Models produced by calls to
:func:`save_model()` and :func:`log_model()`. This Conda environment
contains the current version of PySpark that is installed on the caller's
system. ``dev`` versions of PySpark are replaced with stable versions in
the resulting Conda environment (e.g., if you are running PySpark version
``2.4.5.dev0``, invoking this method produces a Conda environment with a
dependency on PySpark version ``2.4.5``).
get_default_pip_requirements(is_spark_connect_model=False)
Returns:
A list of default pip requirements for MLflow Models produced by this flavor.
Calls to :func:`save_model()` and :func:`log_model()` produce a pip environment
that, at minimum, contains these requirements.
load_model(model_uri, dfs_tmpdir=None, dst_path=None)
Load the Spark MLlib model from the path.
Args:
model_uri: The location, in URI format, of the MLflow model, for example:
- ``/Users/me/path/to/local/model``
- ``relative/path/to/local/model``
- ``s3://my_bucket/path/to/model``
- ``runs:/<mlflow_run_id>/run-relative/path/to/model``
- ``models:/<model_name>/<model_version>``
- ``models:/<model_name>/<stage>``
For more information about supported URI schemes, see
`Referencing Artifacts <https://www.mlflow.org/docs/latest/concepts.html#
artifact-locations>`_.
dfs_tmpdir: Temporary directory path on Distributed (Hadoop) File System (DFS) or local
filesystem if running in local mode. The model is loaded from this
destination. Defaults to ``/tmp/mlflow``.
dst_path: The local filesystem path to which to download the model artifact.
This directory must already exist. If unspecified, a local output
path will be created.
Returns:
pyspark.ml.pipeline.PipelineModel
.. code-block:: python
:caption: Example
import mlflow
model = mlflow.spark.load_model("spark-model")
# Prepare test documents, which are unlabeled (id, text) tuples.
test = spark.createDataFrame(
[(4, "spark i j k"), (5, "l m n"), (6, "spark hadoop spark"), (7, "apache hadoop")],
["id", "text"],
)
# Make predictions on test documents
prediction = model.transform(test)
log_model(spark_model, artifact_path, conda_env=None, code_paths=None, dfs_tmpdir=None, registered_model_name=None, signature: mlflow.models.signature.ModelSignature = None, input_example: Union[pandas.core.frame.DataFrame, numpy.ndarray, dict, list, ForwardRef('csr_matrix'), ForwardRef('csc_matrix'), str, bytes, tuple] = None, await_registration_for=300, pip_requirements=None, extra_pip_requirements=None, metadata=None, **kwargs)
Log a Spark MLlib model as an MLflow artifact for the current run. This uses the
MLlib persistence format and produces an MLflow Model with the Spark flavor.
Note: If no run is active, it will instantiate a run to obtain a run_id.
Args:
spark_model: Spark model to be saved - MLflow can only save descendants of
pyspark.ml.Model or pyspark.ml.Transformer which implement
MLReadable and MLWritable.
.. Note:: The provided Spark model's `transform` method must generate one column
named with "prediction", the column is used as MLflow pyfunc model output.
Most Spark models generate the output column with "prediction" name that
contains prediction labels by default.
To set probability column as the output column for probabilistic
classification models, you need to set "probabilityCol" param to "prediction"
and set "predictionCol" param to "".
(e.g. `model.setProbabilityCol("prediction").setPredictionCol("")`)
artifact_path: Run relative artifact path.
conda_env: Either a dictionary representation of a Conda environment or the path to a conda
environment yaml file. If provided, this describes the environment this model should be run in.
At a minimum, it should specify the dependencies contained in `get_default_conda_env()`.
If ``None``, a conda environment with pip requirements inferred by
:func:`mlflow.models.infer_pip_requirements` is added
to the model. If the requirement inference fails, it falls back to using
`get_default_pip_requirements`. pip requirements from ``conda_env`` are written to a pip
``requirements.txt`` file and the full conda environment is written to ``conda.yaml``.
The following is an *example* dictionary representation of a conda environment::
{
"name": "mlflow-env",
"channels": ["conda-forge"],
"dependencies": [
"python=3.8.15",
{
"pip": [
"pyspark==x.y.z"
],
},
],
}
code_paths: A list of local filesystem paths to Python file dependencies (or directories
containing file dependencies). These files are *prepended* to the system path when the model
is loaded. Files declared as dependencies for a given model should have relative
imports declared from a common root path if multiple files are defined with import dependencies
between them to avoid import errors when loading the model.
For a detailed explanation of ``code_paths`` functionality, recommended usage patterns and
limitations, see the
`code_paths usage guide <https://mlflow.org/docs/latest/model/dependencies.html?highlight=code_paths#saving-extra-code-with-an-mlflow-model>`_.
dfs_tmpdir: Temporary directory path on Distributed (Hadoop) File System (DFS) or local
filesystem if running in local mode. The model is written in this
destination and then copied into the model's artifact directory. This is
necessary as Spark ML models read from and write to DFS if running on a
cluster. If this operation completes successfully, all temporary files
created on the DFS are removed. Defaults to ``/tmp/mlflow``.
For models defined in `pyspark.ml.connect` module, this param is ignored.
registered_model_name: If given, create a model version under
``registered_model_name``, also creating a registered model if one
with the given name does not exist.
signature: A Model Signature object that describes the input and output Schema of the
model. The model signature can be inferred using `infer_signature` function
of `mlflow.models.signature`.
Note if your Spark model contains Spark ML vector type input or output column,
you should create ``SparkMLVector`` vector type for the column,
`infer_signature` function can also infer ``SparkMLVector`` vector type correctly
from Spark Dataframe input / output.
When loading a Spark ML model with ``SparkMLVector`` vector type input as MLflow
pyfunc model, it accepts ``Array[double]`` type input. MLflow internally converts
the array into Spark ML vector and then invoke Spark model for inference. Similarly,
if the model has vector type output, MLflow internally converts Spark ML vector
output data into ``Array[double]`` type inference result.
.. code-block:: python
from mlflow.models import infer_signature
from pyspark.sql.functions import col
from pyspark.ml.classification import LogisticRegression
from pyspark.ml.functions import array_to_vector
import pandas as pd
import mlflow
train_df = spark.createDataFrame(
[([3.0, 4.0], 0), ([5.0, 6.0], 1)], schema="features array<double>, label long"
).select(array_to_vector("features").alias("features"), col("label"))
lor = LogisticRegression(maxIter=2)
lor.setPredictionCol("").setProbabilityCol("prediction")
lor_model = lor.fit(train_df)
test_df = train_df.select("features")
prediction_df = lor_model.transform(train_df).select("prediction")
signature = infer_signature(test_df, prediction_df)
with mlflow.start_run() as run:
model_info = mlflow.spark.log_model(
lor_model,
"model",
signature=signature,
)
# The following signature is outputted:
# inputs:
# ['features': SparkML vector (required)]
# outputs:
# ['prediction': SparkML vector (required)]
print(model_info.signature)
loaded = mlflow.pyfunc.load_model(model_info.model_uri)
test_dataset = pd.DataFrame({"features": [[1.0, 2.0]]})
# `loaded.predict` accepts `Array[double]` type input column,
# and generates `Array[double]` type output column.
print(loaded.predict(test_dataset))
input_example: one or several instances of valid model input. The input example is used
as a hint of what data to feed the model. It will be converted to a Pandas
DataFrame and then serialized to json using the Pandas split-oriented
format, or a numpy array where the example will be serialized to json
by converting it to a list. Bytes are base64-encoded. When the ``signature`` parameter is
``None``, the input example is used to infer a model signature.
await_registration_for: Number of seconds to wait for the model version to finish
being created and is in ``READY`` status. By default, the function
waits for five minutes. Specify 0 or None to skip waiting.
pip_requirements: Either an iterable of pip requirement strings
(e.g. ``["pyspark", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes the environment this model should be run in. If ``None``, a default list of requirements
is inferred by :func:`mlflow.models.infer_pip_requirements` from the current software environment.
If the requirement inference fails, it falls back to using `get_default_pip_requirements`.
Both requirements and constraints are automatically parsed and written to ``requirements.txt`` and
``constraints.txt`` files, respectively, and stored as part of the model. Requirements are also
written to the ``pip`` section of the model's conda environment (``conda.yaml``) file.
extra_pip_requirements: Either an iterable of pip
requirement strings
(e.g. ``["pandas", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes additional pip requirements that are appended to a default set of pip requirements
generated automatically based on the user's current software environment. Both requirements and
constraints are automatically parsed and written to ``requirements.txt`` and ``constraints.txt``
files, respectively, and stored as part of the model. Requirements are also written to the ``pip``
section of the model's conda environment (``conda.yaml``) file.
.. warning::
The following arguments can't be specified at the same time:
- ``conda_env``
- ``pip_requirements``
- ``extra_pip_requirements``
`This example <https://github.com/mlflow/mlflow/blob/master/examples/pip_requirements/pip_requirements.py>`_ demonstrates how to specify pip requirements using
``pip_requirements`` and ``extra_pip_requirements``.
metadata: Custom metadata dictionary passed to the model and stored in the MLmodel file.
kwargs: Extra arguments to pass to the Spark model ``save`` method.
Returns:
A :py:class:`ModelInfo <mlflow.models.model.ModelInfo>` instance that contains the
metadata of the logged model.
.. code-block:: python
:caption: Example
from pyspark.ml import Pipeline
from pyspark.ml.classification import LogisticRegression
from pyspark.ml.feature import HashingTF, Tokenizer
training = spark.createDataFrame(
[
(0, "a b c d e spark", 1.0),
(1, "b d", 0.0),
(2, "spark f g h", 1.0),
(3, "hadoop mapreduce", 0.0),
],
["id", "text", "label"],
)
tokenizer = Tokenizer(inputCol="text", outputCol="words")
hashingTF = HashingTF(inputCol=tokenizer.getOutputCol(), outputCol="features")
lr = LogisticRegression(maxIter=10, regParam=0.001)
pipeline = Pipeline(stages=[tokenizer, hashingTF, lr])
model = pipeline.fit(training)
mlflow.spark.log_model(model, "spark-model")
save_model(spark_model, path, mlflow_model=None, conda_env=None, code_paths=None, dfs_tmpdir=None, signature: mlflow.models.signature.ModelSignature = None, input_example: Union[pandas.core.frame.DataFrame, numpy.ndarray, dict, list, ForwardRef('csr_matrix'), ForwardRef('csc_matrix'), str, bytes, tuple] = None, pip_requirements=None, extra_pip_requirements=None, metadata=None, **kwargs)
Save a Spark MLlib Model to a local path.
By default, this function saves models using the Spark MLlib persistence mechanism.
Args:
spark_model: Spark model to be saved - MLflow can only save descendants of
pyspark.ml.Model or pyspark.ml.Transformer which implement
MLReadable and MLWritable.
path: Local path where the model is to be saved.
mlflow_model: MLflow model config this flavor is being added to.
conda_env: Either a dictionary representation of a Conda environment or the path to a conda
environment yaml file. If provided, this describes the environment this model should be run in.
At a minimum, it should specify the dependencies contained in `get_default_conda_env()`.
If ``None``, a conda environment with pip requirements inferred by
:func:`mlflow.models.infer_pip_requirements` is added
to the model. If the requirement inference fails, it falls back to using
`get_default_pip_requirements`. pip requirements from ``conda_env`` are written to a pip
``requirements.txt`` file and the full conda environment is written to ``conda.yaml``.
The following is an *example* dictionary representation of a conda environment::
{
"name": "mlflow-env",
"channels": ["conda-forge"],
"dependencies": [
"python=3.8.15",
{
"pip": [
"pyspark==x.y.z"
],
},
],
}
code_paths: A list of local filesystem paths to Python file dependencies (or directories
containing file dependencies). These files are *prepended* to the system path when the model
is loaded. Files declared as dependencies for a given model should have relative
imports declared from a common root path if multiple files are defined with import dependencies
between them to avoid import errors when loading the model.
For a detailed explanation of ``code_paths`` functionality, recommended usage patterns and
limitations, see the
`code_paths usage guide <https://mlflow.org/docs/latest/model/dependencies.html?highlight=code_paths#saving-extra-code-with-an-mlflow-model>`_.
dfs_tmpdir: Temporary directory path on Distributed (Hadoop) File System (DFS) or local
filesystem if running in local mode. The model is be written in this
destination and then copied to the requested local path. This is necessary
as Spark ML models read from and write to DFS if running on a cluster. All
temporary files created on the DFS are removed if this operation
completes successfully. Defaults to ``/tmp/mlflow``.
signature: See the document of argument ``signature`` in :py:func:`mlflow.spark.log_model`.
input_example: one or several instances of valid model input. The input example is used
as a hint of what data to feed the model. It will be converted to a Pandas
DataFrame and then serialized to json using the Pandas split-oriented
format, or a numpy array where the example will be serialized to json
by converting it to a list. Bytes are base64-encoded. When the ``signature`` parameter is
``None``, the input example is used to infer a model signature.
pip_requirements: Either an iterable of pip requirement strings
(e.g. ``["pyspark", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes the environment this model should be run in. If ``None``, a default list of requirements
is inferred by :func:`mlflow.models.infer_pip_requirements` from the current software environment.
If the requirement inference fails, it falls back to using `get_default_pip_requirements`.
Both requirements and constraints are automatically parsed and written to ``requirements.txt`` and
``constraints.txt`` files, respectively, and stored as part of the model. Requirements are also
written to the ``pip`` section of the model's conda environment (``conda.yaml``) file.
extra_pip_requirements: Either an iterable of pip
requirement strings
(e.g. ``["pandas", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes additional pip requirements that are appended to a default set of pip requirements
generated automatically based on the user's current software environment. Both requirements and
constraints are automatically parsed and written to ``requirements.txt`` and ``constraints.txt``
files, respectively, and stored as part of the model. Requirements are also written to the ``pip``
section of the model's conda environment (``conda.yaml``) file.
.. warning::
The following arguments can't be specified at the same time:
- ``conda_env``
- ``pip_requirements``
- ``extra_pip_requirements``
`This example <https://github.com/mlflow/mlflow/blob/master/examples/pip_requirements/pip_requirements.py>`_ demonstrates how to specify pip requirements using
``pip_requirements`` and ``extra_pip_requirements``.
metadata: Custom metadata dictionary passed to the model and stored in the MLmodel file.
kwargs: {{ kwargs }}
.. code-block:: python
:caption: Example
from mlflow import spark
from pyspark.ml.pipeline import PipelineModel
# your pyspark.ml.pipeline.PipelineModel type
model = ...
mlflow.spark.save_model(model, "spark-model")
DATA
DEFAULT_AWAIT_MAX_SLEEP_SECONDS = 300
FLAVOR_NAME = 'spark'
INVALID_PARAMETER_VALUE = 1000
LOG_MODEL_PARAM_DOCS = ParamDocs({'name': 'Model name.', 'conda_env': ...
MLFLOW_DFS_TMP = 'MLFLOW_DFS_TMP'
MLMODEL_FILE_NAME = 'MLmodel'
ModelInputExample = typing.Union[pandas.core.frame.DataFrame, numpy......
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\spark\__init__.py
mlflow.start_run
Python Library Documentation: function start_run in module mlflow.tracking.fluent
start_run(run_id: str | None = None, experiment_id: str | None = None, run_name: str | None = None, nested: bool = False, parent_run_id: str | None = None, tags: dict[str, typing.Any] | None = None, description: str | None = None, log_system_metrics: bool | None = None) -> mlflow.tracking.fluent.ActiveRun
Start a new MLflow run, setting it as the active run under which metrics and parameters
will be logged. The return value can be used as a context manager within a ``with`` block;
otherwise, you must call ``end_run()`` to terminate the current run.
If you pass a ``run_id`` or the ``MLFLOW_RUN_ID`` environment variable is set,
``start_run`` attempts to resume a run with the specified run ID and
other parameters are ignored. ``run_id`` takes precedence over ``MLFLOW_RUN_ID``.
If resuming an existing run, the run status is set to ``RunStatus.RUNNING``.
MLflow sets a variety of default tags on the run, as defined in
`MLflow system tags <../../tracking/tracking-api.html#system_tags>`_.
Args:
run_id: If specified, get the run with the specified UUID and log parameters
and metrics under that run. The run's end time is unset and its status
is set to running, but the run's other attributes (``source_version``,
``source_type``, etc.) are not changed.
experiment_id: ID of the experiment under which to create the current run (applicable
only when ``run_id`` is not specified). If ``experiment_id`` argument
is unspecified, will look for valid experiment in the following order:
activated using ``set_experiment``, ``MLFLOW_EXPERIMENT_NAME``
environment variable, ``MLFLOW_EXPERIMENT_ID`` environment variable,
or the default experiment as defined by the tracking server.
run_name: Name of new run, should be a non-empty string. Used only when ``run_id`` is
unspecified. If a new run is created and ``run_name`` is not specified,
a random name will be generated for the run.
nested: Controls whether run is nested in parent run. ``True`` creates a nested run.
parent_run_id: If specified, the current run will be nested under the run with
the specified UUID. The parent run must be in the ACTIVE state.
tags: An optional dictionary of string keys and values to set as tags on the run.
If a run is being resumed, these tags are set on the resumed run. If a new run is
being created, these tags are set on the new run.
description: An optional string that populates the description box of the run.
If a run is being resumed, the description is set on the resumed run.
If a new run is being created, the description is set on the new run.
log_system_metrics: bool, defaults to None. If True, system metrics will be logged
to MLflow, e.g., cpu/gpu utilization. If None, we will check environment variable
`MLFLOW_ENABLE_SYSTEM_METRICS_LOGGING` to determine whether to log system metrics.
System metrics logging is an experimental feature in MLflow 2.8 and subject to change.
Returns:
:py:class:`mlflow.ActiveRun` object that acts as a context manager wrapping the
run's state.
.. code-block:: python
:test:
:caption: Example
import mlflow
# Create nested runs
experiment_id = mlflow.create_experiment("experiment1")
with mlflow.start_run(
run_name="PARENT_RUN",
experiment_id=experiment_id,
tags={"version": "v1", "priority": "P1"},
description="parent",
) as parent_run:
mlflow.log_param("parent", "yes")
with mlflow.start_run(
run_name="CHILD_RUN",
experiment_id=experiment_id,
description="child",
nested=True,
) as child_run:
mlflow.log_param("child", "yes")
print("parent run:")
print(f"run_id: {parent_run.info.run_id}")
print("description: {}".format(parent_run.data.tags.get("mlflow.note.content")))
print("version tag value: {}".format(parent_run.data.tags.get("version")))
print("priority tag value: {}".format(parent_run.data.tags.get("priority")))
print("--")
# Search all child runs with a parent id
query = f"tags.mlflow.parentRunId = '{parent_run.info.run_id}'"
results = mlflow.search_runs(experiment_ids=[experiment_id], filter_string=query)
print("child runs:")
print(results[["run_id", "params.child", "tags.mlflow.runName"]])
# Create a nested run under the existing parent run
with mlflow.start_run(
run_name="NEW_CHILD_RUN",
experiment_id=experiment_id,
description="new child",
parent_run_id=parent_run.info.run_id,
) as child_run:
mlflow.log_param("new-child", "yes")
.. code-block:: text
:caption: Output
parent run:
run_id: 8979459433a24a52ab3be87a229a9cdf
description: starting a parent for experiment 7
version tag value: v1
priority tag value: P1
--
child runs:
run_id params.child tags.mlflow.runName
0 7d175204675e40328e46d9a6a5a7ee6a yes CHILD_RUN
mlflow.start_span
Python Library Documentation: function start_span in module mlflow.tracing.fluent
start_span(name: 'str' = 'span', span_type: 'str | None' = 'UNKNOWN', attributes: 'dict[str, Any] | None' = None, trace_destination: 'TraceLocationBase | None' = None, log_level: 'SpanLogLevel | str | None' = None, run_id: 'str | None' = None, links: 'list[Link] | None' = None) -> 'Generator[LiveSpan, None, None]'
Context manager to create a new span and start it as the current span in the context.
This context manager automatically manages the span lifecycle and parent-child relationships.
The span will be ended when the context manager exits. Any exception raised within the
context manager will set the span status to ``ERROR``, and detailed information such as
exception message and stacktrace will be recorded to the ``attributes`` field of the span.
New spans can be created within the context manager, then they will be assigned as child
spans.
.. code-block:: python
:test:
import mlflow
with mlflow.start_span("my_span") as span:
x = 1
y = 2
span.set_inputs({"x": x, "y": y})
z = x + y
span.set_outputs(z)
span.set_attribute("key", "value")
# do something
When this context manager is used in the top-level scope, i.e. not within another span context,
the span will be treated as a root span. The root span doesn't have a parent reference and
**the entire trace will be logged when the root span is ended**.
.. tip::
If you want more explicit control over the trace lifecycle, you can use
the `mlflow.start_span_no_context()` API. It provides lower
level to start spans and control the parent-child relationships explicitly.
However, it is generally recommended to use this context manager as long as it satisfies
your requirements, because it requires less boilerplate code and is less error-prone.
.. note::
The context manager doesn't propagate the span context across threads by default. see
`Multi Threading <https://mlflow.org/docs/latest/tracing/api/manual-instrumentation#multi-threading>`_
for how to propagate the span context across threads.
Args:
name: The name of the span.
span_type: The type of the span. Can be either a string or
a :py:class:`SpanType <mlflow.entities.SpanType>` enum value
attributes: A dictionary of attributes to set on the span.
trace_destination: The destination to log the trace to, such as MLflow Experiment. If
not provided, the destination will be an active MLflow experiment or an destination
set by the :py:func:`mlflow.tracing.set_destination` function. This parameter
should only be used for root span and setting this for non-root spans will be
ignored with a warning.
log_level: Optional severity level to attach to the span. Accepts a
:py:class:`SpanLogLevel <mlflow.entities.SpanLogLevel>` or its name
(e.g. ``"INFO"``, ``"DEBUG"``). If not provided, the span level is
resolved from the span type at end time.
run_id: The ID of the MLflow run to associate with the trace. This parameter is
only applied when creating a root span. If provided without an explicit
`trace_destination`, the trace will be logged to the run's experiment. If an
active MLflow run is already set via `mlflow.start_run()`, this parameter takes
precedence over the active run.
links: A list of :py:class:`Link <mlflow.entities.Link>` objects to associate with
the span.
Returns:
Yields an :py:class:`mlflow.entities.Span` that represents the created span.
mlflow.start_span_no_context
Python Library Documentation: function start_span_no_context in module mlflow.tracing.fluent
start_span_no_context(name: 'str', span_type: 'str' = 'UNKNOWN', parent_span: 'LiveSpan | None' = None, inputs: 'Any | None' = None, attributes: 'dict[str, str] | None' = None, tags: 'dict[str, str] | None' = None, metadata: 'dict[str, str] | None' = None, experiment_id: 'str | None' = None, start_time_ns: 'int | None' = None, log_level: 'SpanLogLevel | str | None' = None, links: 'list[Link] | None' = None) -> 'LiveSpan'
Start a span without attaching it to the global tracing context.
This is useful when you want to create a span without automatically linking
with a parent span and instead manually manage the parent-child relationships.
The span started with this function must be ended manually using the
`end()` method of the span object.
Args:
name: The name of the span.
span_type: The type of the span. Can be either a string or
a :py:class:`SpanType <mlflow.entities.SpanType>` enum value
parent_span: The parent span to link with. If None, the span will be treated as a root span.
inputs: The input data for the span.
attributes: A dictionary of attributes to set on the span.
tags: A dictionary of tags to set on the trace.
metadata: A dictionary of metadata to set on the trace.
experiment_id: The experiment ID to associate with the trace. If not provided,
the current active experiment will be used.
start_time_ns: The start time of the span in nanoseconds. If not provided,
the current time will be used.
log_level: Optional severity level to attach to the span. Accepts a
:py:class:`SpanLogLevel <mlflow.entities.SpanLogLevel>` or its name
(e.g. ``"INFO"``, ``"DEBUG"``). If not provided, the span level is
resolved from the span type at end time.
links: A list of :py:class:`Link <mlflow.entities.Link>` objects to associate with
the span.
Returns:
A :py:class:`mlflow.entities.Span` that represents the created span.
Example:
.. code-block:: python
:test:
import mlflow
root_span = mlflow.start_span_no_context("my_trace")
# Create a child span
child_span = mlflow.start_span_no_context(
"child_span",
# Manually specify the parent span
parent_span=root_span,
)
# Do something...
child_span.end()
root_span.end()
mlflow.statsmodels
Python Library Documentation: package mlflow.statsmodels in mlflow
NAME
mlflow.statsmodels
DESCRIPTION
The ``mlflow.statsmodels`` module provides an API for logging and loading statsmodels models.
This module exports statsmodels models with the following flavors:
statsmodels (native) format
This is the main flavor that can be loaded back into statsmodels, which relies on pickle
internally to serialize a model.
:py:mod:`mlflow.pyfunc`
Produced for use by generic pyfunc-based deployment tools and batch inference.
.. _statsmodels.base.model.Results:
https://www.statsmodels.org/stable/_modules/statsmodels/base/model.html#Results
PACKAGE CONTENTS
DATA
DEFAULT_AWAIT_MAX_SLEEP_SECONDS = 300
FLAVOR_NAME = 'statsmodels'
LOG_MODEL_PARAM_DOCS = ParamDocs({'name': 'Model name.', 'conda_env': ...
MLFLOW_ALLOW_PICKLE_DESERIALIZATION = 'MLFLOW_ALLOW_PICKLE_DESERIALIZA...
MLMODEL_FILE_NAME = 'MLmodel'
ModelInputExample = typing.Union[pandas.core.frame.DataFrame, numpy......
STATSMODELS_DATA_SUBPATH = 'model.statsmodels'
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\statsmodels\__init__.py
mlflow.store
Python Library Documentation: package mlflow.store in mlflow
NAME
mlflow.store
PACKAGE CONTENTS
_unity_catalog (package)
analytics (package)
artifact (package)
db (package)
db_migrations (package)
entities (package)
fs2db (package)
jobs (package)
model_registry (package)
tracking (package)
workspace (package)
workspace_aware_mixin
workspace_rest_store_mixin
SUBMODULES
abstract_store
artifact_repo
DATA
__all__ = ['abstract_store', 'artifact_repo']
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\store\__init__.py
mlflow.strands
Python Library Documentation: package mlflow.strands in mlflow
NAME
mlflow.strands
PACKAGE CONTENTS
autolog
DATA
FLAVOR_NAME = 'strands'
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\strands\__init__.py
mlflow.system_metrics
Python Library Documentation: package mlflow.system_metrics in mlflow
NAME
mlflow.system_metrics - System metrics logging module.
PACKAGE CONTENTS
metrics (package)
system_metrics_monitor
FUNCTIONS
disable_system_metrics_logging()
Disable system metrics logging globally.
Calling this function will disable system metrics logging globally, but users can still opt in
system metrics logging for individual runs by `mlflow.start_run(log_system_metrics=True)`.
enable_system_metrics_logging()
Enable system metrics logging globally.
Calling this function will enable system metrics logging globally, but users can still opt out
system metrics logging for individual runs by `mlflow.start_run(log_system_metrics=False)`.
set_system_metrics_node_id(node_id)
Set the system metrics node id.
node_id is the identifier of the machine where the metrics are collected. This is useful in
multi-node (distributed training) setup.
set_system_metrics_samples_before_logging(samples)
Set the number of samples before logging system metrics.
Every time `samples` samples have been collected, the system metrics will be logged to mlflow.
By default `samples=1`.
set_system_metrics_sampling_interval(interval)
Set the system metrics sampling interval.
Every `interval` seconds, the system metrics will be collected. By default `interval=10`.
DATA
MLFLOW_ENABLE_SYSTEM_METRICS_LOGGING = 'MLFLOW_ENABLE_SYSTEM_METRICS_L...
MLFLOW_SYSTEM_METRICS_NODE_ID = 'MLFLOW_SYSTEM_METRICS_NODE_ID'
MLFLOW_SYSTEM_METRICS_SAMPLES_BEFORE_LOGGING = 'MLFLOW_SYSTEM_METRICS_...
MLFLOW_SYSTEM_METRICS_SAMPLING_INTERVAL = 'MLFLOW_SYSTEM_METRICS_SAMPL...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\system_metrics\__init__.py
mlflow.telemetry
Python Library Documentation: package mlflow.telemetry in mlflow
NAME
mlflow.telemetry
PACKAGE CONTENTS
client
constant
events
installation_id
schemas
track
utils
FUNCTIONS
get_telemetry_client() -> mlflow.telemetry.client.TelemetryClient | None
set_telemetry_client()
DATA
__all__ = ['get_telemetry_client', 'set_telemetry_client']
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\telemetry\__init__.py
mlflow.tensorflow
Error rendering doc: initialization of _pywrap_checkpoint_reader raised unreported exception
mlflow.test
Python Library Documentation: function test in module mlflow.pytest.decorator
test(fn: 'Callable[_P, _R] | None' = None) -> 'Callable[_P, _R]'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Mark a test function for the MLflow pytest plugin.
Supports both bare ``@mlflow.test`` and ``@mlflow.test()``. Raises at test
time if the plugin is not enabled, instead of silently running the test
without MLflow run/trace management.
mlflow.trace
Python Library Documentation: function trace in module mlflow.tracing.fluent
trace(func: 'Callable[..., Any] | None' = None, name: 'str | None' = None, span_type: 'str' = 'UNKNOWN', attributes: 'dict[str, Any] | None' = None, output_reducer: 'Callable[[list[Any]], Any] | None' = None, trace_destination: 'TraceLocationBase | None' = None, sampling_ratio_override: 'float | None' = None, log_level: 'SpanLogLevel | str | None' = None, links: 'list[Link] | None' = None) -> 'Callable[..., Any]'
A decorator that creates a new span for the decorated function.
When you decorate a function with this :py:func:`@mlflow.trace() <trace>` decorator,
a span will be created for the scope of the decorated function. The span will automatically
capture the input and output of the function. When it is applied to a method, it doesn't
capture the `self` argument. Any exception raised within the function will set the span
status to ``ERROR`` and detailed information such as exception message and stacktrace
will be recorded to the ``attributes`` field of the span.
For example, the following code will yield a span with the name ``"my_function"``,
capturing the input arguments ``x`` and ``y``, and the output of the function.
.. code-block:: python
:test:
import mlflow
@mlflow.trace
def my_function(x, y):
return x + y
This is equivalent to doing the following using the :py:func:`mlflow.start_span` context
manager, but requires less boilerplate code.
.. code-block:: python
:test:
import mlflow
def my_function(x, y):
return x + y
with mlflow.start_span("my_function") as span:
x = 1
y = 2
span.set_inputs({"x": x, "y": y})
result = my_function(x, y)
span.set_outputs({"output": result})
The @mlflow.trace decorator currently support the following types of functions:
.. list-table:: Supported Function Types
:widths: 20 30
:header-rows: 1
* - Function Type
- Supported
* - Sync
- ✅
* - Async
- ✅ (>= 2.16.0)
* - Generator
- ✅ (>= 2.20.2)
* - Async Generator
- ✅ (>= 2.20.2)
* - ClassMethod
- ✅ (>= 3.0.0)
* - StaticMethod
- ✅ (>= 3.0.0)
For more examples of using the @mlflow.trace decorator, including streaming/async
handling, see the `MLflow Tracing documentation <https://www.mlflow.org/docs/latest/tracing/api/manual-instrumentation#decorator>`_.
.. tip::
The @mlflow.trace decorator is useful when you want to trace a function defined by
yourself. However, you may also want to trace a function in external libraries. In
such case, you can use this ``mlflow.trace()`` function to directly wrap the function,
instead of using as the decorator. This will create the exact same span as the
one created by the decorator i.e. captures information from the function call.
.. code-block:: python
:test:
import math
import mlflow
mlflow.trace(math.factorial)(5)
Args:
func: The function to be decorated. Must **not** be provided when using as a decorator.
name: The name of the span. If not provided, the name of the function will be used.
span_type: The type of the span. Can be either a string or a
:py:class:`SpanType <mlflow.entities.SpanType>` enum value.
attributes: A dictionary of attributes to set on the span.
output_reducer: A function that reduces the outputs of the generator function into a
single value to be set as the span output.
trace_destination: The destination to log the trace to, such as MLflow Experiment. If
not provided, the destination will be an active MLflow experiment or an destination
set by the :py:func:`mlflow.tracing.set_destination` function. This parameter
should only be used for root span and setting this for non-root spans will be
ignored with a warning.
sampling_ratio_override: The sampling ratio override for this specific function. Must be
between 0.0 and 1.0. If provided, this overrides the global
``MLFLOW_TRACE_SAMPLING_RATIO`` setting. A value of 1.0 means all traces are sampled,
0.5 means 50% are sampled, and 0.0 means no traces are sampled. If not provided (None),
the global sampling ratio is used. Note: This only applies to root spans; nested calls
always trace if the parent is traced.
log_level: Optional severity level to attach to the span. Accepts a
:py:class:`SpanLogLevel <mlflow.entities.SpanLogLevel>` or its name
(e.g. ``"INFO"``, ``"DEBUG"``). If not provided, the span level is
resolved from the span type at end time.
links: A list of :py:class:`Link <mlflow.entities.Link>` objects to associate with the span.
mlflow.tracing
Python Library Documentation: package mlflow.tracing in mlflow
NAME
mlflow.tracing
PACKAGE CONTENTS
analysis
archival
assessment
attachments
client
config
constant
context
databricks
destination
display (package)
distributed (package)
enablement
export (package)
fluent
locations
otel (package)
processor (package)
provider
sampling
trace_archival_config
trace_archival_service
trace_manager
utils (package)
FUNCTIONS
configure(span_processors: list[typing.Callable[[ForwardRef('LiveSpan')], NoneType]] | None = None) -> mlflow.tracing.config.TracingConfigContext
Configure MLflow tracing. Can be used as function or context manager.
Only updates explicitly provided arguments, leaving others unchanged.
Args:
span_processors: List of functions to process spans before export.
This is helpful for filtering/masking particular attributes from the span to
prevent sensitive data from being logged or for reducing the size of the span.
Each function must accept a single argument of type LiveSpan and should not
return any value. When multiple functions are provided, they are applied
sequentially in the order they are provided.
Returns:
TracingConfigContext: Context manager for temporary configuration changes.
When used as a function, the configuration changes persist.
When used as a context manager, changes are reverted on exit.
Examples:
.. code-block:: python
def pii_filter(span):
"""Example PII filter that masks sensitive data in span attributes."""
# Mask sensitive inputs
if inputs := span.inputs:
for key, value in inputs.items():
if "password" in key.lower() or "token" in key.lower():
span.set_inputs({**inputs, key: "[REDACTED]"})
# Mask sensitive outputs
if outputs := span.outputs:
if isinstance(outputs, dict):
for key in outputs:
if "secret" in key.lower():
outputs[key] = "[REDACTED]"
span.set_outputs(outputs)
# Mask sensitive attributes
for attr_key in list(span.attributes.keys()):
if "api_key" in attr_key.lower():
span.set_attribute(attr_key, "[REDACTED]")
# Permanent configuration change
mlflow.tracing.configure(span_processors=[pii_filter])
# Temporary configuration change
with mlflow.tracing.configure(span_processors=[pii_filter]):
# PII filtering enabled only in this block
pass
context(metadata: 'dict[str, str] | None' = None, tags: 'dict[str, str] | None' = None, enabled: 'bool | None' = None, session_id: 'str | None' = None, user: 'str | None' = None) -> 'Generator[None, None, None]'
A context manager that injects metadata and/or tags into any trace created
within its scope, without creating a wrapper span. It can also be used to
selectively disable tracing within the scope.
This is useful when you need to attach trace-level information (e.g. session
IDs) to traces produced by code you don't control like auto-instrumented libraries,
or when you want to suppress tracing for a specific code block without affecting
the global tracing state.
.. code-block:: python
import mlflow
# Enable auto-tracing for LangChain
mlflow.langchain.autolog()
with mlflow.tracing.context(
session_id="session-123",
user="user-456",
tags={"project": "my-project"},
):
# Any trace created inside this block will carry the metadata and tags.
agent.invoke("What is the capital of France?")
# Disable tracing within a specific block
with mlflow.tracing.context(enabled=False):
# No traces will be created inside this block.
agent.invoke("This call will not be traced")
The context manager can be nested to combine multiple sets of metadata and tags. When same key
is specified in multiple levels, the value from the inner level takes precedence.
.. code-block:: python
import mlflow
with mlflow.tracing.context(metadata={"foo": "bar", "baz": "qux"}):
with mlflow.tracing.context(metadata={"foo": "baz", "qux": "quux"}):
my_func()
# Trace created by my_func will have metadata={"foo": "baz", "baz": "qux", "qux": "quux"}
Args:
metadata: Key-value pairs to inject into the trace's ``request_metadata``
(immutable after trace creation).
tags: Key-value pairs to inject into the trace's ``tags``.
enabled: Whether tracing is enabled within the scope. If ``False``, all
tracing calls within the scope will return ``NoOpSpan`` without creating
any traces. If ``None`` (default), the value is inherited from the outer
scope. This does not affect the global tracing state set by
:py:func:`mlflow.tracing.disable`.
session_id: Session ID to associate with traces created in this scope.
Internally stored as metadata under the ``mlflow.trace.session`` key.
user: User identifier to associate with traces created in this scope.
Internally stored as metadata under the ``mlflow.trace.user`` key.
disable()
Disable tracing.
.. note::
This function sets up `OpenTelemetry` to use
`NoOpTracerProvider <https://github.com/open-telemetry/opentelemetry-python/blob/4febd337b019ea013ccaab74893bd9883eb59000/opentelemetry-api/src/opentelemetry/trace/__init__.py#L222>`_
and effectively disables all tracing operations.
Example:
.. code-block:: python
:test:
import mlflow
@mlflow.trace
def f():
return 0
# Tracing is enabled by default
f()
assert len(mlflow.search_traces(flush=True)) == 1
# Disable tracing
mlflow.tracing.disable()
f()
assert len(mlflow.search_traces(flush=True)) == 1
disable_notebook_display()
Disables displaying the MLflow Trace UI in notebook output cells.
Call :py:func:`mlflow.tracing.enable_notebook_display()` to re-enable display.
enable()
Enable tracing.
Example:
.. code-block:: python
:test:
import mlflow
@mlflow.trace
def f():
return 0
# Tracing is enabled by default
f()
assert len(mlflow.search_traces(flush=True)) == 1
# Disable tracing
mlflow.tracing.disable()
f()
assert len(mlflow.search_traces(flush=True)) == 1
# Re-enable tracing
mlflow.tracing.enable()
f()
assert len(mlflow.search_traces(flush=True)) == 2
enable_notebook_display()
Enables the MLflow Trace UI in notebook output cells. The display is on
by default, and the Trace UI will show up when any of the following operations
are executed:
* On trace completion (i.e. whenever a trace is exported)
* When calling the :py:func:`mlflow.search_traces` fluent API
* When calling the :py:meth:`mlflow.client.MlflowClient.get_trace`
or :py:meth:`mlflow.client.MlflowClient.search_traces` client APIs
To disable, please call :py:func:`mlflow.tracing.disable_notebook_display()`.
get_bridged_tracer_provider() -> opentelemetry.sdk.trace.TracerProvider
Return the OpenTelemetry ``TracerProvider`` that MLflow uses to generate traces.
This is intended for bridging pure-OpenTelemetry instrumentation libraries into MLflow's
tracing pipeline. Many OpenTelemetry instrumentors accept a ``tracer_provider=`` argument
(e.g. ``SomeInstrumentor().instrument(tracer_provider=...)``); passing the provider returned
by this function makes the spans they create flow through MLflow's span processors, so they
receive the correct trace ID and are exported to the configured MLflow destination.
In the default isolated tracer provider mode
(``MLFLOW_USE_DEFAULT_TRACER_PROVIDER=True``) this returns MLflow's isolated provider, so
the bridged spans do not depend on the process-global OpenTelemetry provider pipeline and
the isolation of unrelated OpenTelemetry instrumentation is preserved. In unified mode
(``MLFLOW_USE_DEFAULT_TRACER_PROVIDER=False``) this returns the shared global provider.
.. note::
This bridges where spans are *exported*. For the bridged spans to nest under an active
``@mlflow.trace`` / ``mlflow.start_span`` span, the instrumentor must also read MLflow's
active span as the parent. Instrumentors that read the process-global OpenTelemetry
context can be enabled to do so by setting
``MLFLOW_TRACE_PROPAGATE_TO_OTEL_CONTEXT=True``.
Returns:
The ``TracerProvider`` instance used by MLflow, initializing it if necessary.
get_tracing_context_headers_for_http_request() -> dict[str, str]
Get the http request headers that hold information of the tracing context.
The trace context is serialized as the traceparent header which is defined
in the W3C TraceContext specification.
For details, you can refer to
https://opentelemetry.io/docs/concepts/context-propagation/
and
https://www.w3.org/TR/trace-context/#traceparent-header
Returns:
The http request headers that hold information of the tracing context.
Example (client code):
.. code-block:: python
import mlflow
from mlflow.tracing import get_tracing_context_headers_for_http_request
with mlflow.start_span("client-root") as client_span:
# Get the headers that hold information of the tracing context,
# and send request to remote agent with the headers
headers = get_tracing_context_headers_for_http_request()
resp = requests.post(f"{base_url}/remote_agent_handler", headers=headers)
Example (server handler code):
.. code-block:: python
import mlflow
from flask import Flask, request
from mlflow.tracing import set_tracing_context_from_http_request_headers
app = Flask(__name__)
@app.post("/agent-handler")
def handle():
headers = dict(request.headers)
with set_tracing_context_from_http_request_headers(headers):
with mlflow.start_span("server-handler") as span:
# call agent ...
span.set_attribute("key", "value")
reset()
Reset the flags that indicates whether the MLflow tracer provider has been initialized.
This ensures that the tracer provider is re-initialized when next tracing
operation is performed.
set_databricks_monitoring_sql_warehouse_id(sql_warehouse_id: str, experiment_id: str | None = None) -> None
Set the SQL warehouse ID used for Databricks production monitoring on traces logged to the given
MLflow experiment. This only has an effect for experiments with UC schema as trace location.
Args:
sql_warehouse_id: The SQL warehouse ID to use for monitoring.
experiment_id: The MLflow experiment ID. If not provided, the current active experiment
will be used.
set_destination(destination: mlflow.entities.trace_location.TraceLocationBase, *, context_local: bool = False)
Set a custom span location to which MLflow will export the traces.
A destination specified by this function will take precedence over
other configurations, such as tracking URI, OTLP environment variables.
Args:
destination: A trace location object that specifies the location of the trace data.
Currently, the following locations are supported:
- :py:class:`~mlflow.entities.trace_location.MlflowExperimentLocation`: Logs traces to
an MLflow experiment.
context_local: If False (default), the destination is set globally. If True, the destination
is isolated per async task or thread, providing isolation in concurrent applications.
Example:
**Logging traces to MLflow Experiment:**
.. code-block:: python
from mlflow.entities.trace_location import MlflowExperimentLocation
mlflow.tracing.set_destination(MlflowExperimentLocation(experiment_id="123"))
Note: This has the same effect as setting the active MLflow experiment via the
``MLFLOW_EXPERIMENT_ID`` environment variable or the ``mlflow.set_experiment`` API,
but with narrower scope.
**Isolate the destination between async tasks or threads:**
.. code-block:: python
from mlflow.tracing.destination import Databricks
mlflow.tracing.set_destination(
MlflowExperimentLocation(experiment_id="123"),
context_local=True,
)
The destination set with the ``context_local`` flag will only be effective within the
current async task or thread. This is particularly useful when you want to send traces
to different destinations from a multi-tenant application.
** Reset the destination:**
.. code-block:: python
mlflow.tracing.reset()
set_experiment_trace_location(location: mlflow.entities.trace_location.UCSchemaLocation, experiment_id: str | None = None, sql_warehouse_id: str | None = None) -> mlflow.entities.trace_location.UCSchemaLocation
Configure the storage location for traces of an experiment.
Unity Catalog tables for storing trace data will be created in the specified schema.
When tracing is enabled, all traces for the specified experiment will be
stored in the provided Unity Catalog schema.
.. note::
If the experiment is already linked to a storage location, this will raise an error.
Use `mlflow.tracing.unset_experiment_trace_location` to remove the existing storage
location first and then set a new one.
Args:
location: The storage location for experiment traces in Unity Catalog.
experiment_id: The MLflow experiment ID to set the storage location for.
If not specified, the current active experiment will be used.
sql_warehouse_id: SQL warehouse ID for creating views and querying.
If not specified, uses the value from MLFLOW_TRACING_SQL_WAREHOUSE_ID,
fallback to the default SQL warehouse if the environment variable is not set.
Returns:
The UCSchemaLocation object representing the configured storage location, including
the table names of the spans and logs tables.
Example:
.. code-block:: python
import mlflow
from mlflow.entities import UCSchemaLocation
location = UCSchemaLocation(catalog_name="my_catalog", schema_name="my_schema")
result = mlflow.tracing.set_experiment_trace_location(
location=location,
experiment_id="12345",
)
print(result.full_otel_spans_table_name) # my_catalog.my_schema.otel_spans_table
@mlflow.trace
def add(x):
return x + 1
add(1) # this writes the trace to the storage location set above
set_span_chat_tools(span: 'LiveSpan', tools: 'list[ChatTool]')
Set the `mlflow.chat.tools` attribute on the specified span. This
attribute is used in the UI, and also by downstream applications that
consume trace data, such as MLflow evaluate.
Args:
span: The LiveSpan to add the attribute to
tools: A list of standardized chat tool definitions (refer to the
`spec <../llms/tracing/tracing-schema.html#chat-completion-spans>`_
for details)
Example:
.. code-block:: python
:test:
import mlflow
from mlflow.tracing import set_span_chat_tools
tools = [
{
"type": "function",
"function": {
"name": "add",
"description": "Add two numbers",
"parameters": {
"type": "object",
"properties": {
"a": {"type": "number"},
"b": {"type": "number"},
},
"required": ["a", "b"],
},
},
}
]
@mlflow.trace
def f():
span = mlflow.get_current_active_span()
set_span_chat_tools(span, tools)
return 0
f()
set_tracing_context_from_http_request_headers(headers: dict[str, str])
Context manager to extract the trace context from the http request headers
and set the extracted trace context as the current trace context within the
scope of this context manager.
The trace context must be serialized as the 'traceparent' header which is defined
in the W3C TraceContext specification, please see
:py:func:`mlflow.tracing.get_tracing_context_headers_for_http_request`
for how to get the http request headers.
Args:
headers: The http request headers to extract the trace context from.
Example (client code):
.. code-block:: python
import mlflow
from mlflow.tracing import get_tracing_context_headers_for_http_request
with mlflow.start_span("client-root") as client_span:
# Get the headers that hold information of the tracing context,
# and send request to remote agent with the headers
headers = get_tracing_context_headers_for_http_request()
resp = requests.post(f"{base_url}/remote_agent_handler", headers=headers)
Example (server handler code):
.. code-block:: python
import mlflow
from flask import Flask, request
from mlflow.tracing import set_tracing_context_from_http_request_headers
app = Flask(__name__)
@app.post("/agent-handler")
def handle():
headers = dict(request.headers)
with set_tracing_context_from_http_request_headers(headers):
with mlflow.start_span("server-handler") as span:
# call agent ...
span.set_attribute("key", "value")
unset_experiment_trace_location(location: mlflow.entities.trace_location.UCSchemaLocation, experiment_id: str | None = None) -> None
Unset the storage location for traces of an experiment.
This function removes the experiment storage location configuration,
including the view and the experiment tag.
Args:
location: The storage location to unset.
experiment_id: The MLflow experiment ID to unset the storage location for. If not provided,
the current active experiment will be used.
Example:
.. code-block:: python
import mlflow
from mlflow.entities import UCSchemaLocation
mlflow.tracing.unset_experiment_trace_location(
location=UCSchemaLocation(catalog_name="my_catalog", schema_name="my_schema"),
experiment_id="12345",
)
DATA
__all__ = ['configure', 'context', 'disable', 'enable', 'disable_noteb...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\tracing\__init__.py
mlflow.tracking
Python Library Documentation: package mlflow.tracking in mlflow
NAME
mlflow.tracking
DESCRIPTION
The ``mlflow.tracking`` module provides a Python CRUD interface to MLflow experiments
and runs. This is a lower level API that directly translates to MLflow
`REST API <../rest-api.html>`_ calls.
For a higher level API for managing an "active run", use the :py:mod:`mlflow` module.
PACKAGE CONTENTS
_model_registry (package)
_tracking_service (package)
_uc_upsell
_workspace (package)
artifact_utils
client
context (package)
default_experiment (package)
fluent
metric_value_conversion_utils
multimedia
registry
request_auth (package)
request_header (package)
CLASSES
builtins.object
mlflow.tracking.client.MlflowClient
class MlflowClient(builtins.object)
| MlflowClient(tracking_uri: str | None = None, registry_uri: str | None = None, workspace_store_uri: str | None = None)
|
| Client of an MLflow Tracking Server that creates and manages experiments and runs, and of an
| MLflow Registry Server that creates and manages registered models and model versions. It also
| exposes workspace CRUD via the configured workspace provider. It's a thin wrapper around:
|
| - TrackingServiceClient for tracking operations
| - WorkspaceProviderClient for workspace operations
| - ModelRegistryClient for registry operations
|
| This layered structure provides a unified API while preserving independent implementations.
|
| Methods defined here:
|
| __init__(self, tracking_uri: str | None = None, registry_uri: str | None = None, workspace_store_uri: str | None = None)
| Args:
| tracking_uri: Address of local or remote tracking server. If not provided, defaults
| to the service set by ``mlflow.tracking.set_tracking_uri``. See
| `Where Runs Get Recorded <../tracking.html#where-runs-get-recorded>`_
| for more info.
| registry_uri: Address of local or remote model registry server. If not provided,
| defaults to the service set by ``mlflow.tracking.set_registry_uri``. If
| no such service was set, defaults to the tracking uri of the client.
| workspace_store_uri: Address of the workspace provider backend. Defaults to the tracking
| URI when unspecified, but can be pointed at a dedicated workspace store.
|
| add_dataset_to_experiments(self, dataset_id: str, experiment_ids: list[str]) -> mlflow.entities.evaluation_dataset.EvaluationDataset
| Add a dataset to additional experiments.
|
| This allows reusing datasets across multiple experiments for evaluation purposes.
|
| Args:
| dataset_id: The ID of the dataset to update.
| experiment_ids: List of experiment IDs to associate with the dataset.
|
| Returns:
| The updated EvaluationDataset with new experiment associations.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Add dataset to new experiments
| dataset = client.add_dataset_to_experiments(
| dataset_id="d-abc123", experiment_ids=["1", "2", "3"]
| )
| print(f"Dataset now associated with {len(dataset.experiment_ids)} experiments")
|
| copy_model_version(self, src_model_uri, dst_name) -> mlflow.entities.model_registry.model_version.ModelVersion
| Copy a model version from one registered model to another as a new model version.
| If the destination model does not exist, it will be created.
|
| This method can also be used to migrate model versions from the Databricks workspace
| registry to Unity Catalog. During the migration, signature validation can be bypassed
| by setting the `MLFLOW_SKIP_SIGNATURE_CHECK_FOR_UC_REGISTRY_MIGRATION`environment
| variable to `True`.
|
| Args:
| src_model_uri: The model URI of the model version to copy. This must be a model
| registry URI with a `"models:/"` scheme (e.g., `"models:/iris_model@champion"`).
| dst_name: The name of the registered model to copy the model version to. If a
| registered model with this name does not exist, it will be created.
|
| Returns:
| Single :py:class:`mlflow.entities.model_registry.ModelVersion` object representing
| the copied model version.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_version_info(mv):
| print(f"Name: {mv.name}")
| print(f"Version: {mv.version}")
| print(f"Source: {mv.source}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
|
| # Log a model
| with mlflow.start_run() as run:
| params = {"n_estimators": 3, "random_state": 42}
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Create source model version
| client = MlflowClient()
| src_name = "RandomForestRegression-staging"
| client.create_registered_model(src_name)
| src_uri = f"runs:/{run.info.run_id}/sklearn-model"
| mv_src = client.create_model_version(src_name, src_uri, run.info.run_id)
| print_model_version_info(mv_src)
| print("--")
|
| # Copy the source model version into a new registered model
| dst_name = "RandomForestRegression-production"
| src_model_uri = f"models:/{mv_src.name}/{mv_src.version}"
| mv_copy = client.copy_model_version(src_model_uri, dst_name)
| print(f"Name: {mv_copy.name}, Version: {mv_copy.version}, Source: {mv_copy.source}")
|
| .. code-block:: python
| :caption: Migration example from Databricks Workspace Model Registry to Unity Catalog
|
| from mlflow import MlflowClient
| import os
|
| os.environ["MLFLOW_SKIP_SIGNATURE_CHECK_FOR_UC_REGISTRY_MIGRATION"] = "true"
| client = MlflowClient(registry_uri="databricks")
|
| src_model_uri = f"models:/my_workspace_model/1"
| uc_model_dst_name = "mycatalog.myschema.my_uc_model"
| uc_migrated_copy = client.copy_model_version(src_model_uri, uc_model_dst_name)
| print_model_version_info(uc_migrated_copy)
|
| .. code-block:: text
| :caption: Output
|
| Name: RandomForestRegression-staging
| Version: 1
| Source: runs:/53e08bb38f0c487fa36c5872515ed998/sklearn-model
| --
| Name: RandomForestRegression-production
| Version: 1
| Source: models:/RandomForestRegression-staging/1
|
| create_dataset(self, name: str, experiment_id: str | list[str] | None = None, tags: dict[str, typing.Any] | None = None) -> mlflow.entities.evaluation_dataset.EvaluationDataset
| Create a new dataset.
|
| Args:
| name: The name of the dataset.
| experiment_id: Optional experiment ID (str) or list of experiment IDs to
| associate with the dataset.
| tags: Optional dictionary of tags to apply to the dataset.
|
| Returns:
| The created EvaluationDataset object.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Create a dataset associated with experiments
| dataset = client.create_dataset(
| name="qa_evaluation_v1",
| experiment_id=["0", "1"],
| tags={"environment": "production", "version": "1.0"},
| )
|
| create_experiment(self, name: str, artifact_location: str | None = None, tags: dict[str, typing.Any] | None = None) -> str
| Create an experiment.
|
| Args:
| name: The experiment name, which must be a unique string.
| artifact_location: The location to store run artifacts. If not provided, the server
| picks anappropriate default.
| tags: A dictionary of key-value pairs that are converted into
| :py:class:`mlflow.entities.ExperimentTag` objects, set as
| experiment tags upon experiment creation.
|
| Returns:
| String as an integer ID of the created experiment.
|
| .. code-block:: python
| :caption: Example
|
| from pathlib import Path
| from mlflow import MlflowClient
|
| # Create an experiment with a name that is unique and case sensitive.
| client = MlflowClient()
| experiment_id = client.create_experiment(
| "Social NLP Experiments",
| artifact_location=Path.cwd().joinpath("mlruns").as_uri(),
| tags={"version": "v1", "priority": "P1"},
| )
| client.set_experiment_tag(experiment_id, "nlp.framework", "Spark NLP")
|
| # Fetch experiment metadata information
| experiment = client.get_experiment(experiment_id)
| print(f"Name: {experiment.name}")
| print(f"Experiment_id: {experiment.experiment_id}")
| print(f"Artifact Location: {experiment.artifact_location}")
| print(f"Tags: {experiment.tags}")
| print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
|
| .. code-block:: text
| :caption: Output
|
| Name: Social NLP Experiments
| Experiment_id: 1
| Artifact Location: file:///.../mlruns
| Tags: {'version': 'v1', 'priority': 'P1', 'nlp.framework': 'Spark NLP'}
| Lifecycle_stage: active
|
| create_logged_model(self, experiment_id: str, name: str | None = None, source_run_id: str | None = None, tags: dict[str, str] | None = None, params: dict[str, str] | None = None, model_type: str | None = None) -> mlflow.entities.logged_model.LoggedModel
| Create a new logged model.
|
| Args:
| experiment_id: ID of the experiment to which the model belongs.
| name: Name of the model. If not specified, a random name will be generated.
| source_run_id: ID of the run that produced the model.
| tags: Tags to set on the model.
| params: Parameters to set on the model.
| model_type: The type of the model. This is a user-defined string that can be used to
| search and compare related models. For example, setting
| ``model_type="agent"`` enables you to easily search for this model and
| compare it to other models of type ``"agent"`` in the future.
|
| Returns:
| The created model.
|
| create_mcp_access_endpoint(self, server_name: str, url: str, transport_type: mlflow.entities.mcp_server.MCPRemoteTransportType = <MCPRemoteTransportType.STREAMABLE_HTTP: 'streamable-http'>, server_version: str | None = None, server_alias: str | None = None) -> mlflow.entities.mcp_access_endpoint.MCPAccessEndpoint
|
| create_mcp_server(self, name: str, description: str | None = None, icons: list[mlflow.store.tracking.mcp_server_registry.abstract_mixin.MCPIcon] | None = None) -> mlflow.entities.mcp_server.MCPServer
|
| create_mcp_server_version(self, server_json: dict[str, typing.Any], source: str | None = None, status: mlflow.entities.mcp_server.MCPStatus | None = None, tools: list[mlflow.entities.mcp_server.MCPTool] | None = <object object at 0x0000025F348EA210>, connect_options: dict[str, mlflow.entities.mcp_server_version.ConnectOptionSettings] | None = None) -> mlflow.entities.mcp_server_version.MCPServerVersion
|
| create_model_version(self, name: str, source: str, run_id: str | None = None, tags: dict[str, typing.Any] | None = None, run_link: str | None = None, description: str | None = None, await_creation_for: int = 300, model_id: str | None = None) -> mlflow.entities.model_registry.model_version.ModelVersion
| Create a new model version from given source.
|
| Args:
| name: Name for the containing registered model.
| source: URI indicating the location of the model artifacts. The artifact URI can be
| run relative (e.g. ``runs:/<run_id>/<model_artifact_path>``), a model
| registry URI (e.g. ``models:/<model_name>/<version>``), or other URIs
| supported by the model registry backend (e.g. `"s3://my_bucket/my/model"`).
| run_id: Run ID from MLflow tracking server that generated the model.
| tags: A dictionary of key-value pairs that are converted into
| :py:class:`mlflow.entities.model_registry.ModelVersionTag` objects.
| run_link: Link to the run from an MLflow tracking server that generated this model.
| description: Description of the version.
| await_creation_for: Number of seconds to wait for the model version to finish being
| created and is in ``READY`` status. By default, the function
| waits for five minutes. Specify 0 or None to skip waiting.
| model_id: The ID of the model (from an Experiment) that is being promoted to a
| registered model version, if applicable.
|
| Returns:
| Single :py:class:`mlflow.entities.model_registry.ModelVersion` object created by
| backend.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow.store.artifact.runs_artifact_repo import RunsArtifactRepository
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a new version of the rfr model under the registered model name
| desc = "A new version of the model"
| runs_uri = f"runs:/{run.info.run_id}/sklearn-model"
| model_src = RunsArtifactRepository.get_underlying_uri(runs_uri)
| mv = client.create_model_version(name, model_src, run.info.run_id, description=desc)
| print(f"Name: {mv.name}")
| print(f"Version: {mv.version}")
| print(f"Description: {mv.description}")
| print(f"Status: {mv.status}")
| print(f"Stage: {mv.current_stage}")
|
| .. code-block:: text
| :caption: Output
|
| Name: RandomForestRegression
| Version: 1
| Description: A new version of the model
| Status: READY
| Stage: None
|
| create_prompt(self, name: str, description: str | None = None, tags: dict[str, str] | None = None) -> mlflow.entities.model_registry.prompt.Prompt
| Create a new prompt in the registry.
|
| This method delegates directly to the store, providing full Unity Catalog support
| when used with Unity Catalog registries.
|
| Args:
| name: Name of the prompt.
| description: Optional description of the prompt.
| tags: Optional dictionary of prompt tags.
|
| Returns:
| A Prompt object.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| prompt_info = client.create_prompt(
| name="my_prompt",
| description="A helpful prompt",
| tags={"team": "data-science"},
| )
|
| create_prompt_version(self, name: str, template: str | list[dict[str, typing.Any]], description: str | None = None, tags: dict[str, str] | None = None, response_format: type[pydantic.main.BaseModel] | dict[str, typing.Any] | None = None, model_config: 'PromptModelConfig | dict[str, Any] | None' = None) -> mlflow.entities.model_registry.prompt_version.PromptVersion
| Create a new version of an existing prompt.
|
| This method delegates directly to the store, providing full Unity Catalog support
| when used with Unity Catalog registries.
|
| Args:
| name: Name of the prompt.
| template: The prompt template content for this version.
| description: Optional description of the prompt version.
| tags: Optional dictionary of prompt version tags.
| response_format: Optional Pydantic class or dictionary defining the expected response
| structure. This can be used to specify the schema for structured
| outputs from LLM calls.
| model_config: Optional PromptModelConfig object or dictionary defining the model
| configuration (model name, parameters, etc.) to use when invoking this
| prompt version.
|
| Returns:
| A PromptVersion object.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| prompt_version = client.create_prompt_version(
| name="my_prompt",
| template="Respond as a {{style}} assistant: {{query}}",
| description="Added style parameter",
| tags={"author": "alice"},
| )
|
| create_registered_model(self, name: str, tags: dict[str, typing.Any] | None = None, description: str | None = None, deployment_job_id: str | None = None) -> mlflow.entities.model_registry.registered_model.RegisteredModel
| Create a new registered model in backend store.
|
| Args:
| name: Name of the new model. This is expected to be unique in the backend store.
| tags: A dictionary of key-value pairs that are converted into
| :py:class:`mlflow.entities.model_registry.RegisteredModelTag` objects.
| description: Description of the model.
| deployment_job_id: Optional deployment job ID.
|
| Returns:
| A single object of :py:class:`mlflow.entities.model_registry.RegisteredModel`
| created by backend.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
|
| def print_registered_model_info(rm):
| print(f"name: {rm.name}")
| print(f"tags: {rm.tags}")
| print(f"description: {rm.description}")
|
|
| name = "SocialMediaTextAnalyzer"
| tags = {"nlp.framework": "Spark NLP"}
| desc = "This sentiment analysis model classifies the tone-happy, sad, angry."
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| client = MlflowClient()
| client.create_registered_model(name, tags, desc)
| print_registered_model_info(client.get_registered_model(name))
|
| .. code-block:: text
| :caption: Output
|
| name: SocialMediaTextAnalyzer
| tags: {'nlp.framework': 'Spark NLP'}
| description: This sentiment analysis model classifies the tone-happy, sad, angry.
|
| create_run(self, experiment_id: str, start_time: int | None = None, tags: dict[str, typing.Any] | None = None, run_name: str | None = None) -> mlflow.entities.run.Run
| Create a :py:class:`mlflow.entities.Run` object that can be associated with
| metrics, parameters, artifacts, etc.
| Unlike :py:func:`mlflow.projects.run`, creates objects but does not run code.
| Unlike :py:func:`mlflow.start_run`, does not change the "active run" used by
| :py:func:`mlflow.log_param`.
|
| Args:
| experiment_id: The string ID of the experiment to create a run in.
| start_time: If not provided, use the current timestamp.
| tags: A dictionary of key-value pairs that are converted into
| :py:class:`mlflow.entities.RunTag` objects.
| run_name: The name of this run.
|
| Returns:
| :py:class:`mlflow.entities.Run` that was created.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| # Create a run with a tag under the default experiment (whose id is '0').
| tags = {"engineering": "ML Platform"}
| name = "platform-run-24"
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id, tags=tags, run_name=name)
|
| # Show newly created run metadata info
| print(f"Run tags: {run.data.tags}")
| print(f"Experiment id: {run.info.experiment_id}")
| print(f"Run id: {run.info.run_id}")
| print(f"Run name: {run.info.run_name}")
| print(f"lifecycle_stage: {run.info.lifecycle_stage}")
| print(f"status: {run.info.status}")
|
| .. code-block:: text
| :caption: Output
|
| Run tags: {'engineering': 'ML Platform'}
| Experiment id: 0
| Run id: 65fb9e2198764354bab398105f2e70c1
| Run name: platform-run-24
| lifecycle_stage: active
| status: RUNNING
|
| create_webhook(self, name: str, url: str, events: list[typing.Union[typing.Literal['registered_model.created', 'model_version.created', 'model_version_tag.set', 'model_version_tag.deleted', 'model_version_alias.created', 'model_version_alias.deleted', 'prompt.created', 'prompt_version.created', 'prompt_tag.set', 'prompt_tag.deleted', 'prompt_version_tag.set', 'prompt_version_tag.deleted', 'prompt_alias.created', 'prompt_alias.deleted', 'budget_policy.exceeded'], mlflow.entities.webhook.WebhookEvent]], description: str | None = None, secret: str | None = None, status: str | mlflow.entities.webhook.WebhookStatus | None = None) -> mlflow.entities.webhook.Webhook
| Create a new webhook.
|
| Args:
| name: Name for the webhook.
| url: Webhook endpoint URL.
| events: List of events that trigger this webhook. Can be strings or
| `WebhookEvent` objects.
| description: Optional description of the webhook.
| secret: Optional secret for HMAC signature verification.
| status: Webhook status (defaults to ACTIVE). Can be string or WebhookStatus enum.
| Valid statuses: "ACTIVE", "DISABLED"
|
| Returns:
| A :py:class:`mlflow.entities.webhook.Webhook` object representing the created webhook.
|
| create_workspace(self, name: str, description: str | None = None, default_artifact_root: str | None = None, trace_archival_config: mlflow.entities.workspace.TraceArchivalConfig | None = None) -> mlflow.entities.workspace.Workspace
| Create a new workspace.
|
| Args:
| name: The workspace name (alphanumeric, hyphens, underscores only).
| description: Optional description of the workspace.
| default_artifact_root: Optional artifact root URI; falls back to server default.
| trace_archival_config: Optional Python-side grouping for trace archival settings.
| Use ``TraceArchivalConfig.location`` to set the archival storage URI/root and
| ``TraceArchivalConfig.retention`` to set the archived-trace retention duration such
| as ``30d`` or ``12h``. Leave fields as ``None`` to omit them from the create
| request.
|
| Returns:
| The newly created workspace.
|
| delete_dataset(self, dataset_id: str) -> None
| Delete a dataset and all its records.
|
| Args:
| dataset_id: The ID of the dataset to delete.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Delete a dataset
| client.delete_dataset("dataset_123")
|
| delete_dataset_tag(self, dataset_id: str, key: str) -> None
| Delete a tag from a dataset.
|
| Args:
| dataset_id: The ID of the dataset.
| key: The tag key to delete.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Delete a tag
| client.delete_dataset_tag(dataset_id="dataset123", key="deprecated")
|
| delete_experiment(self, experiment_id: str) -> None
| Delete an experiment from the backend store.
|
| This deletion is a soft-delete, not a permanent deletion. Experiment names can not be
| reused, unless the deleted experiment is permanently deleted by a database admin.
|
| Args:
| experiment_id: The experiment ID returned from ``create_experiment``.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| # Create an experiment with a name that is unique and case sensitive
| client = MlflowClient()
| experiment_id = client.create_experiment("New Experiment")
| client.delete_experiment(experiment_id)
|
| # Examine the deleted experiment details.
| experiment = client.get_experiment(experiment_id)
| print(f"Name: {experiment.name}")
| print(f"Artifact Location: {experiment.artifact_location}")
| print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
|
| .. code-block:: text
| :caption: Output
|
| Name: New Experiment
| Artifact Location: file:///.../mlruns/1
| Lifecycle_stage: deleted
|
| delete_experiment_tag(self, experiment_id: str, key: str) -> None
| Delete a tag from the experiment with the specified ID.
|
| Args:
| experiment_id: String ID of the experiment.
| key: Name of the tag to be deleted.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| # Create an experiment and set its tag
| client = MlflowClient()
| experiment_id = client.create_experiment("Social Media NLP Experiments")
| client.set_experiment_tag(experiment_id, "nlp.framework", "Spark NLP")
|
| # Fetch experiment metadata information, validate that tag is set
| experiment = client.get_experiment(experiment_id)
| assert experiment.tags == {"nlp.framework": "Spark NLP"}
|
| client.delete_experiment_tag(experiment_id, "nlp.framework")
|
| # Fetch experiment metadata information, validate that tag is deleted
| experiment = client.get_experiment(experiment_id)
| assert experiment.tags == {}
|
| delete_logged_model(self, model_id: str) -> None
| Delete the logged model with the specified ID.
|
| Args:
| model_id: ID of the model to delete.
|
| delete_logged_model_tag(self, model_id: str, key: str) -> None
| Delete a tag from the specified logged model.
|
| Args:
| model_id: ID of the model.
| key: Tag key to delete.
|
| delete_mcp_access_endpoint(self, server_name: str, endpoint_id: str) -> None
|
| delete_mcp_server(self, name: str) -> None
|
| delete_mcp_server_alias(self, name: str, alias: str) -> None
|
| delete_mcp_server_tag(self, name: str, key: str) -> None
|
| delete_mcp_server_version(self, name: str, version: str) -> None
|
| delete_mcp_server_version_tag(self, name: str, version: str, key: str) -> None
|
| delete_model_version(self, name: str, version: str) -> None
| Delete model version in backend.
|
| Args:
| name: Name of the containing registered model.
| version: Version number of the model version.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_models_info(mv):
| for m in mv:
| print(f"name: {m.name}")
| print(f"latest version: {m.version}")
| print(f"run_id: {m.run_id}")
| print(f"current_stage: {m.current_stage}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
|
| # Create two runs and log MLflow entities
| with mlflow.start_run() as run1:
| params = {"n_estimators": 3, "random_state": 42}
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| with mlflow.start_run() as run2:
| params = {"n_estimators": 6, "random_state": 42}
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| name = "RandomForestRegression"
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a two versions of the rfr model under the registered model name
| for run_id in [run1.info.run_id, run2.info.run_id]:
| model_uri = f"runs:/{run_id}/sklearn-model"
| mv = client.create_model_version(name, model_uri, run_id)
| print(f"model version {mv.version} created")
|
| print("--")
|
| # Fetch latest version; this will be version 2
| models = client.get_latest_versions(name, stages=["None"])
| print_models_info(models)
| print("--")
|
| # Delete the latest model version 2
| print(f"Deleting model version {mv.version}")
| client.delete_model_version(name, mv.version)
| models = client.get_latest_versions(name, stages=["None"])
| print_models_info(models)
|
| .. code-block:: text
| :caption: Output
|
| model version 1 created
| model version 2 created
| --
| name: RandomForestRegression
| latest version: 2
| run_id: 9881172ef10f4cb08df3ed452c0c362b
| current_stage: None
| --
| Deleting model version 2
| name: RandomForestRegression
| latest version: 1
| run_id: 9165d4f8aa0a4d069550824bdc55caaf
| current_stage: None
|
| delete_model_version_tag(self, name: str, version: str | None = None, key: str | None = None, stage: str | None = None) -> None
| Delete a tag associated with the model version.
|
| When stage is set, tag will be deleted for latest model version of the stage.
| Setting both version and stage parameter will result in error.
|
| Args:
| name: Registered model name.
| version: Registered model version.
| key: Tag key. key is required.
| stage: Registered model stage.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_version_info(mv):
| print(f"Name: {mv.name}")
| print(f"Version: {mv.version}")
| print(f"Tags: {mv.tags}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a new version of the rfr model under the registered model name
| # and delete a tag
| model_uri = f"runs:/{run.info.run_id}/sklearn-model"
| tags = {"t": "1", "t1": "2"}
| mv = client.create_model_version(name, model_uri, run.info.run_id, tags=tags)
| print_model_version_info(mv)
| print("--")
| # using version to delete tag
| client.delete_model_version_tag(name, mv.version, "t")
|
| # using stage to delete tag
| client.delete_model_version_tag(name, key="t1", stage=mv.current_stage)
| mv = client.get_model_version(name, mv.version)
| print_model_version_info(mv)
|
| .. code-block:: text
| :caption: Output
|
| Name: RandomForestRegression
| Version: 1
| Tags: {'t': '1', 't1': '2'}
| --
| Name: RandomForestRegression
| Version: 1
| Tags: {}
|
| delete_prompt(self, name: str) -> None
| Delete a prompt from the registry.
|
| For Unity Catalog registries, this method first checks if any versions exist for the prompt
| and throws an error if undeleted versions are found. All versions must be explicitly
| deleted first before the prompt itself can be deleted.
|
| For other registries, the prompt is deleted normally without version checking.
|
| Args:
| name: Name of the prompt to delete.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # For Unity Catalog, delete all versions first
| if client.get_registry_uri().startswith("databricks-uc"):
| versions = client.search_prompt_versions("my_prompt")
| for version in versions:
| client.delete_prompt_version("my_prompt", version.version)
|
| # Then delete the prompt
| client.delete_prompt("my_prompt")
|
| delete_prompt_alias(self, name: str, alias: str) -> None
| Delete an alias for a :py:class:`Prompt <mlflow.entities.Prompt>`.
|
| Args:
| name: The name of the prompt.
| alias: The alias to delete for the prompt.
|
| delete_prompt_tag(self, name: str, key: str) -> None
| Delete a tag from a prompt.
|
| This method delegates directly to the store, providing full Unity Catalog support
| when used with Unity Catalog registries.
|
| Args:
| name: Name of the prompt.
| key: Tag key to delete.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| client.delete_prompt_tag("my_prompt", "environment")
|
| delete_prompt_version(self, name: str, version: str) -> None
| Delete a specific prompt version.
|
| This method delegates directly to the store, providing full Unity Catalog support
| when used with Unity Catalog registries.
|
| Args:
| name: Name of the prompt.
| version: Version of the prompt to delete.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| client.delete_prompt_version("my_prompt", "1")
|
| delete_prompt_version_tag(self, name: str, version: str | int, key: str) -> None
| Delete a tag from a specific prompt version.
|
| Args:
| name: The name of the prompt.
| version: The version number of the prompt.
| key: The tag key to delete.
|
| delete_registered_model(self, name: str)
| Delete registered model.
| Backend raises exception if a registered model with given name does not exist.
|
| Args:
| name: Name of the registered model to delete.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
|
| def print_registered_models_info(r_models):
| print("--")
| for rm in r_models:
| print(f"name: {rm.name}")
| print(f"tags: {rm.tags}")
| print(f"description: {rm.description}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| client = MlflowClient()
|
| # Register a couple of models with respective names, tags, and descriptions
| for name, tags, desc in [
| ("name1", {"t1": "t1"}, "description1"),
| ("name2", {"t2": "t2"}, "description2"),
| ]:
| client.create_registered_model(name, tags, desc)
|
| # Fetch all registered models
| print_registered_models_info(client.search_registered_models())
|
| # Delete one registered model and fetch again
| client.delete_registered_model("name1")
| print_registered_models_info(client.search_registered_models())
|
| .. code-block:: text
| :caption: Output
|
| --
| name: name1
| tags: {'t1': 't1'}
| description: description1
| name: name2
| tags: {'t2': 't2'}
| description: description2
| --
| name: name2
| tags: {'t2': 't2'}
| description: description2
|
| delete_registered_model_alias(self, name: str, alias: str) -> None
| Delete an alias associated with a registered model.
|
| Args:
| name: Registered model name.
| alias: Name of the alias.
|
| .. code-block:: Python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_info(rm):
| print("--Model--")
| print("name: {}".format(rm.name))
| print("aliases: {}".format(rm.aliases))
|
|
| def print_model_version_info(mv):
| print("--Model Version--")
| print("Name: {}".format(mv.name))
| print("Version: {}".format(mv.version))
| print("Aliases: {}".format(mv.aliases))
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, artifact_path="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
| model = client.get_registered_model(name)
| print_model_info(model)
|
| # Create a new version of the rfr model under the registered model name
| model_uri = "runs:/{}/sklearn-model".format(run.info.run_id)
| mv = client.create_model_version(name, model_uri, run.info.run_id)
| print_model_version_info(mv)
|
| # Set registered model alias
| client.set_registered_model_alias(name, "test-alias", mv.version)
| print()
| print_model_info(model)
| print_model_version_info(mv)
|
| # Delete registered model alias
| client.delete_registered_model_alias(name, "test-alias")
| print()
| print_model_info(model)
| print_model_version_info(mv)
|
| .. code-block:: text
| :caption: Output
|
| --Model--
| name: RandomForestRegression
| aliases: {}
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: []
|
| --Model--
| name: RandomForestRegression
| aliases: {"test-alias": "1"}
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: ["test-alias"]
|
| --Model--
| name: RandomForestRegression
| aliases: {}
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: []
|
| delete_registered_model_tag(self, name: str, key: str) -> None
| Delete a tag associated with the registered model.
|
| Args:
| name: Registered model name.
| key: Registered model tag key.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
|
| def print_registered_models_info(r_models):
| print("--")
| for rm in r_models:
| print(f"name: {rm.name}")
| print(f"tags: {rm.tags}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| client = MlflowClient()
|
| # Register a couple of models with respective names and tags
| for name, tags in [("name1", {"t1": "t1"}), ("name2", {"t2": "t2"})]:
| client.create_registered_model(name, tags)
|
| # Fetch all registered models
| print_registered_models_info(client.search_registered_models())
| # Delete a tag from model `name2`
| client.delete_registered_model_tag("name2", "t2")
| print_registered_models_info(client.search_registered_models())
|
| .. code-block:: text
| :caption: Output
|
| --
| name: name1
| tags: {'t1': 't1'}
| name: name2
| tags: {'t2': 't2'}
| --
| name: name1
| tags: {'t1': 't1'}
| name: name2
| tags: {}
|
| delete_run(self, run_id: str) -> None
| Deletes a run with the given ID.
|
| Args:
| run_id: The unique run id to delete.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| # Create a run under the default experiment (whose id is '0').
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| run_id = run.info.run_id
| print(f"run_id: {run_id}; lifecycle_stage: {run.info.lifecycle_stage}")
| print("--")
| client.delete_run(run_id)
| del_run = client.get_run(run_id)
| print(f"run_id: {run_id}; lifecycle_stage: {del_run.info.lifecycle_stage}")
|
| .. code-block:: text
| :caption: Output
|
| run_id: a61c7a1851324f7094e8d5014c58c8c8; lifecycle_stage: active
| run_id: a61c7a1851324f7094e8d5014c58c8c8; lifecycle_stage: deleted
|
| delete_tag(self, run_id: str, key: str) -> None
| Delete a tag from a run. This is irreversible.
|
| Args:
| run_id: String ID of the run.
| key: Name of the tag.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_run_info(run):
| print(f"run_id: {run.info.run_id}")
| print(f"Tags: {run.data.tags}")
|
|
| # Create a run under the default experiment (whose id is '0').
| client = MlflowClient()
| tags = {"t1": 1, "t2": 2}
| experiment_id = "0"
| run = client.create_run(experiment_id, tags=tags)
| print_run_info(run)
| print("--")
|
| # Delete tag and fetch updated info
| client.delete_tag(run.info.run_id, "t1")
| run = client.get_run(run.info.run_id)
| print_run_info(run)
|
| .. code-block:: text
| :caption: Output
|
| run_id: b7077267a59a45d78cd9be0de4bc41f5
| Tags: {'t2': '2', 't1': '1'}
| --
| run_id: b7077267a59a45d78cd9be0de4bc41f5
| Tags: {'t2': '2'}
|
| delete_trace_tag(self, trace_id: str, key: str) -> None
| .. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
|
| Delete a tag on the trace with the given trace ID.
|
| The trace can be an active one or the one that has already ended and recorded in the
| backend. Below is an example of deleting a tag on an active trace. You can replace the
| ``trace_id`` parameter to delete a tag on an already ended trace.
|
| .. code-block:: python
| :test:
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| root_span = client.start_trace("my_trace", tags={"key": "value"})
| client.delete_trace_tag(root_span.trace_id, "key")
| client.end_trace(root_span.trace_id)
|
| Args:
| trace_id: The ID of the trace to delete the tag from.
| key: The string key of the tag. Must be at most 250 characters long, otherwise
| it will be truncated when stored.
|
| delete_traces(self, experiment_id: str, max_timestamp_millis: int | None = None, max_traces: int | None = None, trace_ids: list[str] | None = None) -> int
| Delete traces based on the specified criteria.
|
| - Either `max_timestamp_millis` or `trace_ids` must be specified, but not both.
| - `max_traces` can't be specified if `trace_ids` is specified.
|
| Args:
| experiment_id: ID of the associated experiment.
| max_timestamp_millis: The maximum timestamp in milliseconds since the UNIX epoch for
| deleting traces. Traces older than or equal to this timestamp will be deleted.
| max_traces: The maximum number of traces to delete. If max_traces is specified, and
| it is less than the number of traces that would be deleted based on the
| max_timestamp_millis, the oldest traces will be deleted first.
| trace_ids: A set of trace IDs to delete.
|
| Returns:
| The number of traces deleted.
|
| Example:
|
| .. code-block:: python
| :test:
|
| import mlflow
| import time
|
| client = mlflow.MlflowClient()
|
| # Delete all traces in the experiment
| client.delete_traces(
| experiment_id="0", max_timestamp_millis=time.time_ns() // 1_000_000
| )
|
| # Delete traces based on max_timestamp_millis and max_traces
| # Older traces will be deleted first.
| some_timestamp = time.time_ns() // 1_000_000
| client.delete_traces(
| experiment_id="0", max_timestamp_millis=some_timestamp, max_traces=2
| )
|
| # Delete traces based on trace_ids
| client.delete_traces(experiment_id="0", trace_ids=["id_1", "id_2"])
|
| delete_webhook(self, webhook_id: str) -> None
| Delete a webhook.
|
| Args:
| webhook_id: Webhook ID to delete.
|
| Returns:
| None
|
| delete_workspace(self, name: str, mode: str = <WorkspaceDeletionMode.RESTRICT: 'RESTRICT'>) -> None
| Delete an existing workspace.
|
| Args:
| name: Name of the workspace to delete.
| mode: Deletion mode — ``"SET_DEFAULT"``, ``"CASCADE"``, or ``"RESTRICT"``.
|
| detach_prompt_from_run(self, run_id: str, prompt_uri: str) -> None
| Detach a prompt registered within the MLflow Prompt Registry from an MLflow Run.
|
| Args:
| run_id: The ID of the run to log the prompt to.
| prompt_uri: The prompt URI in the format "prompts:/name/version".
|
| download_artifacts(self, run_id: str, path: str, dst_path: str | None = None) -> str
| Download an artifact file or directory from a run to a local directory if applicable,
| and return a local path for it.
|
| Args:
| run_id: The run to download artifacts from.
| path: Relative source path to the desired artifact.
| dst_path: Absolute path of the local filesystem destination directory to which to
| download the specified artifacts. This directory must already exist.
| If unspecified, the artifacts will either be downloaded to a new
| uniquely-named directory on the local filesystem or will be returned
| directly in the case of the LocalArtifactRepository.
|
| Returns:
| Local path of desired artifact.
|
| .. code-block:: python
| :caption: Example
|
| import os
| import mlflow
| from mlflow import MlflowClient
|
| features = "rooms, zipcode, median_price, school_rating, transport"
| with open("features.txt", "w") as f:
| f.write(features)
|
| # Log artifacts
| with mlflow.start_run() as run:
| mlflow.log_artifact("features.txt", artifact_path="features")
|
| # Download artifacts
| client = MlflowClient()
| local_dir = "/tmp/artifact_downloads"
| if not os.path.exists(local_dir):
| os.mkdir(local_dir)
| local_path = client.download_artifacts(run.info.run_id, "features", local_dir)
| print(f"Artifacts downloaded in: {local_path}")
| print(f"Artifacts: {os.listdir(local_path)}")
|
| .. code-block:: text
| :caption: Output
|
| Artifacts downloaded in: /tmp/artifact_downloads/features
| Artifacts: ['features.txt']
|
| end_span(self, trace_id: str, span_id: str, outputs: typing.Any | None = None, attributes: dict[str, typing.Any] | None = None, status: mlflow.entities.span_status.SpanStatus | str = 'OK', end_time_ns: int | None = None)
| .. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
|
| End the span with the given trace ID and span ID.
|
| Args:
| trace_id: The ID of the trace to end.
| span_id: The ID of the span to end.
| outputs: Outputs to set on the span.
| attributes: A dictionary of attributes to set on the span. If the span already has
| attributes, the new attributes will be merged with the existing ones. If the same
| key already exists, the new value will overwrite the old one.
| status: The status of the span. This can be a
| :py:class:`SpanStatus <mlflow.entities.SpanStatus>` object or a string
| representing the status code defined in
| :py:class:`SpanStatusCode <mlflow.entities.SpanStatusCode>`
| e.g. ``"OK"``, ``"ERROR"``. The default status is OK.
| end_time_ns: The end time of the span in nano seconds since the UNIX epoch.
| If not provided, the current time will be used.
|
| end_trace(self, trace_id: str, outputs: typing.Any | None = None, attributes: dict[str, typing.Any] | None = None, status: mlflow.entities.span_status.SpanStatus | str = 'OK', end_time_ns: int | None = None)
| .. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
|
| End the trace with the given trace ID. This will end the root span of the trace and
| log the trace to the backend if configured.
|
| If any of children spans are not ended, they will be ended forcefully with the status
| ``TRACE_STATUS_UNSPECIFIED``. If the trace is already ended, this method will have
| no effect.
|
| Args:
| trace_id: The ID of the trace to end.
| outputs: Outputs to set on the trace.
| attributes: A dictionary of attributes to set on the trace. If the trace already
| has attributes, the new attributes will be merged with the existing ones.
| If the same key already exists, the new value will overwrite the old one.
| status: The status of the trace. This can be a
| :py:class:`SpanStatus <mlflow.entities.SpanStatus>` object or a string
| representing the status code defined in
| :py:class:`SpanStatusCode <mlflow.entities.SpanStatusCode>`
| e.g. ``"OK"``, ``"ERROR"``. The default status is OK.
| end_time_ns: The end time of the trace in nanoseconds since the UNIX epoch.
|
| finalize_logged_model(self, model_id: str, status: Union[Literal['READY', 'FAILED'], mlflow.entities.logged_model_status.LoggedModelStatus]) -> mlflow.entities.logged_model.LoggedModel
| Finalize a model by updating its status.
|
| Args:
| model_id: ID of the model to finalize.
| status: Final status to set on the model.
|
| Returns:
| The updated model.
|
| get_dataset(self, dataset_id: str) -> mlflow.entities.evaluation_dataset.EvaluationDataset
| Get a dataset by ID.
|
| Args:
| dataset_id: The ID of the dataset to retrieve.
|
| Returns:
| The EvaluationDataset object.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Get a dataset by ID (assuming it exists)
| dataset = client.get_dataset("dataset_123")
|
| # Access records (lazy loaded)
| df = dataset.to_df()
|
| get_experiment(self, experiment_id: str) -> mlflow.entities.experiment.Experiment
| Retrieve an experiment by experiment_id from the backend store
|
| Args:
| experiment_id: The experiment ID returned from ``create_experiment``.
|
| Returns:
| :py:class:`mlflow.entities.Experiment`
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| exp_id = client.create_experiment("Experiment")
| experiment = client.get_experiment(exp_id)
|
| # Show experiment info
| print(f"Name: {experiment.name}")
| print(f"Experiment ID: {experiment.experiment_id}")
| print(f"Artifact Location: {experiment.artifact_location}")
| print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
|
| .. code-block:: text
| :caption: Output
|
| Name: Experiment
| Experiment ID: 1
| Artifact Location: file:///.../mlruns/1
| Lifecycle_stage: active
|
| get_experiment_by_name(self, name: str) -> mlflow.entities.experiment.Experiment | None
| Retrieve an experiment by experiment name from the backend store
|
| Args:
| name: The experiment name, which is case sensitive.
|
| Returns:
| An instance of :py:class:`mlflow.entities.Experiment`
| if an experiment with the specified name exists, otherwise None.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| # Case-sensitive name
| client = MlflowClient()
| experiment = client.get_experiment_by_name("Default")
| # Show experiment info
| print(f"Name: {experiment.name}")
| print(f"Experiment ID: {experiment.experiment_id}")
| print(f"Artifact Location: {experiment.artifact_location}")
| print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
|
| .. code-block:: text
| :caption: Output
|
| Name: Default
| Experiment ID: 0
| Artifact Location: file:///.../mlruns/0
| Lifecycle_stage: active
|
| get_latest_mcp_server_version(self, name: str) -> mlflow.entities.mcp_server_version.MCPServerVersion
|
| get_latest_versions(self, name: str, stages: list[str] | None = None) -> list[mlflow.entities.model_registry.model_version.ModelVersion]
| .. Warning:: ``mlflow.tracking.client.MlflowClient.get_latest_versions`` is deprecated since 2.9.0. Model registry stages will be removed in a future major release. To learn more about the deprecation of model registry stages, see our migration guide here: https://mlflow.org/docs/latest/model-registry.html#migrating-from-stages
|
| Latest version models for each requests stage. If no ``stages`` provided, returns the
| latest version for each stage.
|
| Args:
| name: Name of the registered model from which to get the latest versions.
| stages: List of desired stages. If input list is None, return latest versions for
| for ALL_STAGES.
|
| Returns:
| List of :py:class:`mlflow.entities.model_registry.ModelVersion` objects.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_models_info(mv):
| for m in mv:
| print(f"name: {m.name}")
| print(f"latest version: {m.version}")
| print(f"run_id: {m.run_id}")
| print(f"current_stage: {m.current_stage}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| # Create two runs Log MLflow entities
| with mlflow.start_run() as run1:
| params = {"n_estimators": 3, "random_state": 42}
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
| with mlflow.start_run() as run2:
| params = {"n_estimators": 6, "random_state": 42}
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
| # Register model name in the model registry
| name = "RandomForestRegression"
| client = MlflowClient()
| client.create_registered_model(name)
| # Create a two versions of the rfr model under the registered model name
| for run_id in [run1.info.run_id, run2.info.run_id]:
| model_uri = f"runs:/{run_id}/sklearn-model"
| mv = client.create_model_version(name, model_uri, run_id)
| print(f"model version {mv.version} created")
| # Fetch latest version; this will be version 2
| print("--")
| print_models_info(client.get_latest_versions(name, stages=["None"]))
|
| .. code-block:: text
| :caption: Output
|
| model version 1 created
| model version 2 created
| --
| name: RandomForestRegression
| latest version: 2
| run_id: 31165664be034dc698c52a4bdeb71663
| current_stage: None
|
| get_logged_model(self, model_id: str) -> mlflow.entities.logged_model.LoggedModel
| Fetch the logged model with the specified ID.
|
| Args:
| model_id: ID of the model to fetch.
|
| Returns:
| The fetched model.
|
| get_mcp_access_endpoint(self, server_name: str, endpoint_id: str) -> mlflow.entities.mcp_access_endpoint.MCPAccessEndpoint
|
| get_mcp_server(self, name: str) -> mlflow.entities.mcp_server.MCPServer
|
| get_mcp_server_version(self, name: str, version: str) -> mlflow.entities.mcp_server_version.MCPServerVersion
|
| get_mcp_server_version_by_alias(self, name: str, alias: str) -> mlflow.entities.mcp_server_version.MCPServerVersion
|
| get_metric_history(self, run_id: str, key: str) -> list[mlflow.entities.metric.Metric]
| Return a list of metric objects corresponding to all values logged for a given metric.
|
| Args:
| run_id: Unique identifier for run.
| key: Metric name within the run.
|
| Returns:
| A list of :py:class:`mlflow.entities.Metric` entities if logged, else empty list.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_metric_info(history):
| for m in history:
| print(f"name: {m.key}")
| print(f"value: {m.value}")
| print(f"step: {m.step}")
| print(f"timestamp: {m.timestamp}")
| print("--")
|
|
| # Create a run under the default experiment (whose id is "0"). Since this is low-level
| # CRUD operation, the method will create a run. To end the run, you'll have
| # to explicitly end it.
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| print(f"run_id: {run.info.run_id}")
| print("--")
|
| # Log couple of metrics, update their initial value, and fetch each
| # logged metrics' history.
| for k, v in [("m1", 1.5), ("m2", 2.5)]:
| client.log_metric(run.info.run_id, k, v, step=0)
| client.log_metric(run.info.run_id, k, v + 1, step=1)
| print_metric_info(client.get_metric_history(run.info.run_id, k))
| client.set_terminated(run.info.run_id)
|
| .. code-block:: text
| :caption: Output
|
| run_id: c360d15714994c388b504fe09ea3c234
| --
| name: m1
| value: 1.5
| step: 0
| timestamp: 1603423788607
| --
| name: m1
| value: 2.5
| step: 1
| timestamp: 1603423788608
| --
| name: m2
| value: 2.5
| step: 0
| timestamp: 1603423788609
| --
| name: m2
| value: 3.5
| step: 1
| timestamp: 1603423788610
| --
|
| get_model_version(self, name: str, version: str) -> mlflow.entities.model_registry.model_version.ModelVersion
| Converts the docstring args and returns to google style.
|
| Args:
| name: Name of the containing registered model.
| version: Version number as an integer of the model version.
|
| Returns:
| A single :py:class:`mlflow.entities.model_registry.ModelVersion` object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
|
| # Create two runs Log MLflow entities
| with mlflow.start_run() as run1:
| params = {"n_estimators": 3, "random_state": 42}
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| with mlflow.start_run() as run2:
| params = {"n_estimators": 6, "random_state": 42}
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| name = "RandomForestRegression"
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a two versions of the rfr model under the registered model name
| for run_id in [run1.info.run_id, run2.info.run_id]:
| model_uri = f"runs:/{run_id}/sklearn-model"
| mv = client.create_model_version(name, model_uri, run_id)
| print(f"model version {mv.version} created")
| print("--")
|
| # Fetch the last version; this will be version 2
| mv = client.get_model_version(name, mv.version)
| print(f"Name: {mv.name}")
| print(f"Version: {mv.version}")
|
| .. code-block:: text
| :caption: Output
|
| model version 1 created
| model version 2 created
| --
| Name: RandomForestRegression
| Version: 2
|
| get_model_version_by_alias(self, name: str, alias: str) -> mlflow.entities.model_registry.model_version.ModelVersion
| Get the model version instance by name and alias.
|
| Args:
| name: Registered model name.
| alias: Name of the alias.
|
| Returns:
| A single :py:class:`mlflow.entities.model_registry.ModelVersion` object.
|
| .. code-block:: Python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_info(rm):
| print("--Model--")
| print("name: {}".format(rm.name))
| print("aliases: {}".format(rm.aliases))
|
|
| def print_model_version_info(mv):
| print("--Model Version--")
| print("Name: {}".format(mv.name))
| print("Version: {}".format(mv.version))
| print("Aliases: {}".format(mv.aliases))
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, artifact_path="sklearn-model", signature=signature)
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
| model = client.get_registered_model(name)
| print_model_info(model)
| # Create a new version of the rfr model under the registered model name
| model_uri = "runs:/{}/sklearn-model".format(run.info.run_id)
| mv = client.create_model_version(name, model_uri, run.info.run_id)
| print_model_version_info(mv)
| # Set registered model alias
| client.set_registered_model_alias(name, "test-alias", mv.version)
| print()
| print_model_info(model)
| print_model_version_info(mv)
| # Get model version by alias
| alias_mv = client.get_model_version_by_alias(name, "test-alias")
| print()
| print_model_version_info(alias_mv)
|
| .. code-block:: text
| :caption: Output
|
| --Model--
| name: RandomForestRegression
| aliases: {}
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: []
| --Model--
| name: RandomForestRegression
| aliases: {"test-alias": "1"}
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: ["test-alias"]
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: ["test-alias"]
|
| get_model_version_download_uri(self, name: str, version: str) -> str
| Get the download location in Model Registry for this model version.
|
| Args:
| name: Name of the containing registered model.
| version: Version number as an integer of the model version.
|
| Returns:
| A single URI location that allows reads for downloading.
|
| .. code-block:: python
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a new version of the rfr model under the registered model name
| model_uri = f"runs:/{run.info.run_id}/sklearn-model"
| mv = client.create_model_version(name, model_uri, run.info.run_id)
| artifact_uri = client.get_model_version_download_uri(name, mv.version)
| print(f"Download URI: {artifact_uri}")
|
| .. code-block:: text
|
| Download URI: runs:/027d7bbe81924c5a82b3e4ce979fcab7/sklearn-model
|
| get_model_version_stages(self, name: str, version: str) -> list[str]
| .. Warning:: ``mlflow.tracking.client.MlflowClient.get_model_version_stages`` is deprecated since 2.9.0. Model registry stages will be removed in a future major release. To learn more about the deprecation of model registry stages, see our migration guide here: https://mlflow.org/docs/latest/model-registry.html#migrating-from-stages
|
| This is a docstring. Here is info.
|
| Returns:
| A list of valid stages.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a new version of the rfr model under the registered model name
| # fetch valid stages
| model_uri = f"runs:/{run.info.run_id}/models/sklearn-model"
| mv = client.create_model_version(name, model_uri, run.info.run_id)
| stages = client.get_model_version_stages(name, mv.version)
| print(f"Model list of valid stages: {stages}")
|
| .. code-block:: text
| :caption: Output
|
| Model list of valid stages: ['None', 'Staging', 'Production', 'Archived']
|
| get_parent_run(self, run_id: str) -> mlflow.entities.run.Run | None
| Gets the parent run for the given run id if one exists.
|
| Args:
| run_id: Unique identifier for the child run.
|
| Returns:
| A single :py:class:`mlflow.entities.Run` object, if the parent run exists. Otherwise,
| returns None.
|
| .. code-block:: python
| :test:
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
| # Create nested runs
| with mlflow.start_run():
| with mlflow.start_run(nested=True) as child_run:
| child_run_id = child_run.info.run_id
|
| client = MlflowClient()
| parent_run = client.get_parent_run(child_run_id)
|
| print(f"child_run_id: {child_run_id}")
| print(f"parent_run_id: {parent_run.info.run_id}")
|
| .. code-block:: text
| :caption: Output
|
| child_run_id: 7d175204675e40328e46d9a6a5a7ee6a
| parent_run_id: 8979459433a24a52ab3be87a229a9cdf
|
| get_prompt(self, name: str) -> mlflow.entities.model_registry.prompt.Prompt | None
| Get prompt metadata by name.
|
| Args:
| name: Name of the prompt.
|
| Returns:
| A Prompt object containing prompt metadata, or None if not found.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| prompt = client.get_prompt("my_prompt")
| if prompt:
| print(f"Prompt: {prompt.name}")
| print(f"Description: {prompt.description}")
|
| get_prompt_version(self, name: str, version: str | int) -> mlflow.entities.model_registry.prompt_version.PromptVersion | None
| Get a specific prompt version.
|
| This method delegates directly to the store, providing full Unity Catalog support
| when used with Unity Catalog registries.
|
| Args:
| name: Name of the prompt.
| version: Version of the prompt (number or alias).
|
| Returns:
| A PromptVersion object with the specific version content, or None if not found.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| prompt_version = client.get_prompt_version("my_prompt", "1")
| prompt_alias = client.get_prompt_version("my_prompt", "production")
|
| get_prompt_version_by_alias(self, name: str, alias: str) -> mlflow.entities.model_registry.prompt_version.PromptVersion
| Get a prompt version by alias.
|
| This method delegates directly to the store, providing full Unity Catalog support
| when used with Unity Catalog registries.
|
| Args:
| name: Name of the prompt.
| alias: Alias of the prompt version.
|
| Returns:
| A PromptVersion object.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| prompt_version = client.get_prompt_version_by_alias("my_prompt", "production")
|
| get_registered_model(self, name: str) -> mlflow.entities.model_registry.registered_model.RegisteredModel
| Get a registered model.
|
| Args:
| name: Name of the registered model to get.
|
| Returns:
| A single :py:class:`mlflow.entities.model_registry.RegisteredModel` object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
|
| def print_model_info(rm):
| print("--")
| print(f"name: {rm.name}")
| print(f"tags: {rm.tags}")
| print(f"description: {rm.description}")
|
|
| name = "SocialMediaTextAnalyzer"
| tags = {"nlp.framework": "Spark NLP"}
| desc = "This sentiment analysis model classifies the tone-happy, sad, angry."
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| client = MlflowClient()
| # Create and fetch the registered model
| client.create_registered_model(name, tags, desc)
| model = client.get_registered_model(name)
| print_model_info(model)
|
| .. code-block:: text
| :caption: Output
|
| --
| name: SocialMediaTextAnalyzer
| tags: {'nlp.framework': 'Spark NLP'}
| description: This sentiment analysis model classifies the tone-happy, sad, angry.
|
| get_run(self, run_id: str) -> mlflow.entities.run.Run
| Fetch the run from backend store. The resulting :py:class:`Run <mlflow.entities.Run>`
| contains a collection of run metadata -- :py:class:`RunInfo <mlflow.entities.RunInfo>`,
| as well as a collection of run parameters, tags, and metrics --
| :py:class:`RunData <mlflow.entities.RunData>`. It also contains a collection of run
| inputs (experimental), including information about datasets used by the run --
| :py:class:`RunInputs <mlflow.entities.RunInputs>`. In the case where multiple metrics with
| the same key are logged for the run, the :py:class:`RunData <mlflow.entities.RunData>`
| contains the most recently logged value at the largest step for each metric.
|
| Args:
| run_id: Unique identifier for the run.
|
| Returns:
| A single :py:class:`mlflow.entities.Run` object, if the run exists. Otherwise,
| raises an exception.
|
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
| with mlflow.start_run() as run:
| mlflow.log_param("p", 0)
|
| # The run has finished since we have exited the with block
| # Fetch the run
| client = MlflowClient()
| run = client.get_run(run.info.run_id)
| print(f"run_id: {run.info.run_id}")
| print(f"params: {run.data.params}")
| print(f"status: {run.info.status}")
|
| .. code-block:: text
| :caption: Output
|
| run_id: e36b42c587a1413ead7c3b6764120618
| params: {'p': '0'}
| status: FINISHED
|
| get_trace(self, trace_id: str, display=True, flush: bool = False) -> mlflow.entities.trace.Trace
| .. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
|
| Get the trace matching the specified ``trace_id``.
|
| Args:
| trace_id: String ID of the trace to fetch.
| display: If ``True``, display the trace on the notebook.
| flush: If ``True``, flush any pending async trace writes before fetching.
| Useful in tests or scripts where async logging may not have completed.
| Default to ``False``.
|
| Returns:
| The retrieved :py:class:`Trace <mlflow.entities.Trace>`.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| trace_id = "12345678"
| trace = client.get_trace(trace_id)
|
| get_webhook(self, webhook_id: str) -> mlflow.entities.webhook.Webhook
| Get webhook instance by ID.
|
| Args:
| webhook_id: Webhook ID.
|
| Returns:
| A :py:class:`mlflow.entities.webhook.Webhook` object.
|
| get_workspace(self, name: str) -> mlflow.entities.workspace.Workspace
| Return metadata for the specified workspace.
|
| get_workspace_store_uri(self) -> str
| Return the resolved workspace provider URI. This value is always non-null because
| `resolve_workspace_store_uri()` falls back to the tracking URI when no workspace URI is
| explicitly provided.
|
| link_prompt_version_to_model(self, name: str, version: str, model_id: str) -> None
| Link a prompt version to a model.
|
| Args:
| name: The name of the prompt.
| version: The version of the prompt.
| model_id: The ID of the model to link the prompt version to.
|
| link_prompt_version_to_run(self, run_id: str, prompt: str | mlflow.entities.model_registry.prompt_version.PromptVersion) -> None
| Link a prompt registered within the MLflow Prompt Registry with an MLflow Run.
|
| .. warning::
|
| This API is not thread-safe. If you are linking prompts from multiple threads,
| consider using a lock to ensure that only one thread links a prompt to a run at a time.
|
| Args:
| run_id: The ID of the run to link the prompt to.
| prompt: A Prompt object or the prompt URI in the format "prompts:/name/version".
|
| link_prompt_versions_to_trace(self, prompt_versions: list[mlflow.entities.model_registry.prompt_version.PromptVersion], trace_id: str) -> None
| Link multiple prompt versions to a trace.
|
| Args:
| prompt_versions: List of PromptVersion objects to link.
| trace_id: Trace ID to link to each prompt version.
|
| Example:
| .. code-block:: python
|
| import mlflow
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Get prompt versions and link to trace
| prompt_v1 = client.get_prompt_version("my_prompt", "1")
| prompt_v2 = client.get_prompt_version("another_prompt", "2")
|
| client.link_prompt_versions_to_trace(
| prompt_versions=[prompt_v1, prompt_v2],
| trace_id="trace_123",
| )
|
| link_traces_to_run(self, trace_ids: list[str], run_id: str) -> None
| Link multiple traces to a run by creating entity associations.
|
| Args:
| trace_ids: List of trace IDs to link to the run. Maximum 100 traces allowed.
| run_id: ID of the run to link traces to.
|
| Example:
| .. code-block:: python
|
| import mlflow
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Link multiple traces to a run
| client.link_traces_to_run(
| trace_ids=["trace_123", "trace_456", "trace_789"],
| run_id="run_abc",
| )
|
| list_artifacts(self, run_id: str, path=None) -> list[mlflow.entities.file_info.FileInfo]
| List the artifacts for a run.
|
| Args:
| run_id: The run to list artifacts from.
| path: The run's relative artifact path to list from. By default it is set to None
| or the root artifact path.
|
| Returns:
| List of :py:class:`mlflow.entities.FileInfo`
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_artifact_info(artifact):
| print(f"artifact: {artifact.path}")
| print(f"is_dir: {artifact.is_dir}")
| print(f"size: {artifact.file_size}")
|
|
| features = "rooms zipcode, median_price, school_rating, transport"
| labels = "price"
|
| # Create a run under the default experiment (whose id is '0').
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
|
| # Create some artifacts and log under the above run
| for file, content in [("features", features), ("labels", labels)]:
| with open(f"{file}.txt", "w") as f:
| f.write(content)
| client.log_artifact(run.info.run_id, f"{file}.txt")
|
| # Fetch the logged artifacts
| artifacts = client.list_artifacts(run.info.run_id)
| for artifact in artifacts:
| print_artifact_info(artifact)
| client.set_terminated(run.info.run_id)
|
| .. code-block:: text
| :caption: Output
|
| artifact: features.txt
| is_dir: False
| size: 53
| artifact: labels.txt
| is_dir: False
| size: 5
|
| list_logged_model_artifacts(self, model_id: str, path: str | None = None) -> list[mlflow.entities.file_info.FileInfo]
|
| list_logged_prompts(self, run_id: str) -> list[mlflow.entities.model_registry.prompt_version.PromptVersion]
| List all prompts associated with an MLflow Run.
|
| Args:
| run_id: The ID of the run to list the prompts for.
|
| Returns:
| A list of :py:class:`Prompt <mlflow.entities.Prompt>` objects associated with the run.
|
| list_webhooks(self, max_results: int | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.webhook.Webhook]
| List webhooks.
|
| Args:
| max_results: Maximum number of webhooks to return.
| page_token: Token specifying the next page of results.
|
| Returns:
| A :py:class:`mlflow.store.entities.paged_list.PagedList` of Webhook objects.
|
| list_workspaces(self) -> list[mlflow.entities.workspace.Workspace]
| Return the list of workspaces available to the current user.
|
| load_prompt(self, name_or_uri: str, version: str | int | None = None, allow_missing: bool = False, cache_ttl_seconds: float | None = None) -> mlflow.entities.model_registry.prompt_version.PromptVersion | None
| Load a :py:class:`Prompt <mlflow.entities.Prompt>` from the MLflow Prompt Registry.
|
| The prompt can be specified by name and version, or by URI.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient(registry_uri="sqlite:///prompt_registry.db")
|
| # Load a specific version of the prompt by name and version
| prompt = client.load_prompt("my_prompt", version=1)
|
| # Load a specific version of the prompt by URI
| prompt = client.load_prompt("prompts:/my_prompt/1")
|
| Args:
| name_or_uri: The name of the prompt, or the URI in the format "prompts:/name/version".
| version: The version of the prompt (required when using name, not allowed when
| using URI).
| allow_missing: If True, return None instead of raising Exception if the specified prompt
| is not found.
| cache_ttl_seconds: Time-to-live for caching the prompt in seconds. If None, uses
| the value from `MLFLOW_ALIAS_PROMPT_CACHE_TTL_SECONDS` environment variable for
| alias-based prompts (default 60), and the value from
| `MLFLOW_VERSION_PROMPT_CACHE_TTL_SECONDS` environment variable for version-based
| prompts (default None, no TTL). Set to 0 to disable caching.
|
| load_table(self, experiment_id: str, artifact_file: str, run_ids: list[str] | None = None, extra_columns: list[str] | None = None) -> 'pandas.DataFrame'
| Load a table from MLflow Tracking as a pandas.DataFrame. The table is loaded from the
| specified artifact_file in the specified run_ids. The extra_columns are columns that
| are not in the table but are augmented with run information and added to the DataFrame.
|
| Args:
| experiment_id: The experiment ID to load the table from.
| artifact_file: The run-relative artifact file path in posixpath format to which
| table to load (e.g. "dir/file.json").
| run_ids: Optional list of run_ids to load the table from. If no run_ids are
| specified, the table is loaded from all runs in the current experiment.
| extra_columns: Optional list of extra columns to add to the returned DataFrame
| For example, if extra_columns=["run_id"], then the returned DataFrame
| will have a column named run_id.
|
| Returns:
| pandas.DataFrame containing the loaded table if the artifact exists
| or else throw a MlflowException.
|
| .. code-block:: python
| :test:
| :caption: Example with passing run_ids
|
| import mlflow
| import pandas as pd
| from mlflow import MlflowClient
|
| table_dict = {
| "inputs": ["What is MLflow?", "What is Databricks?"],
| "outputs": ["MLflow is ...", "Databricks is ..."],
| "toxicity": [0.0, 0.0],
| }
| df = pd.DataFrame.from_dict(table_dict)
| client = MlflowClient()
| run = client.create_run(experiment_id="0")
| client.log_table(run.info.run_id, data=df, artifact_file="qabot_eval_results.json")
| loaded_table = client.load_table(
| experiment_id="0",
| artifact_file="qabot_eval_results.json",
| run_ids=[
| run.info.run_id,
| ],
| # Append a column containing the associated run ID for each row
| extra_columns=["run_id"],
| )
|
| .. code-block:: python
| :test:
| :caption: Example with passing no run_ids
|
| # Loads the table with the specified name for all runs in the given
| # experiment and joins them together
| import mlflow
| import pandas as pd
| from mlflow import MlflowClient
|
| table_dict = {
| "inputs": ["What is MLflow?", "What is Databricks?"],
| "outputs": ["MLflow is ...", "Databricks is ..."],
| "toxicity": [0.0, 0.0],
| }
| df = pd.DataFrame.from_dict(table_dict)
| client = MlflowClient()
| run = client.create_run(experiment_id="0")
| client.log_table(run.info.run_id, data=df, artifact_file="qabot_eval_results.json")
| loaded_table = client.load_table(
| experiment_id="0",
| artifact_file="qabot_eval_results.json",
| # Append the run ID and the parent run ID to the table
| extra_columns=["run_id"],
| )
|
| log_artifact(self, run_id, local_path, artifact_path=None) -> None
| Write a local file or directory to the remote ``artifact_uri``.
|
| Args:
| run_id: String ID of run.
| local_path: Path to the file or directory to write.
| artifact_path: If provided, the directory in ``artifact_uri`` to write to.
|
| .. code-block:: python
| :caption: Example
|
| import tempfile
| from pathlib import Path
|
| from mlflow import MlflowClient
|
| # Create a run under the default experiment (whose id is '0').
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
|
| # log and fetch the artifact
| with tempfile.TemporaryDirectory() as tmp_dir:
| path = Path(tmp_dir, "features.txt")
| path.write_text(features)
| client.log_artifact(run.info.run_id, path)
|
| artifacts = client.list_artifacts(run.info.run_id)
| for artifact in artifacts:
| print(f"artifact: {artifact.path}")
| print(f"is_dir: {artifact.is_dir}")
| client.set_terminated(run.info.run_id)
|
| .. code-block:: text
| :caption: Output
|
| artifact: features.txt
| is_dir: False
|
| log_artifacts(self, run_id: str, local_dir: str, artifact_path: str | None = None) -> None
| Write a directory of files to the remote ``artifact_uri``.
|
| Args:
| run_id: String ID of run.
| local_dir: Path to the directory of files to write.
| artifact_path: If provided, the directory in ``artifact_uri`` to write to.
|
| .. code-block:: python
| :caption: Example
|
| import json
| import tempfile
| from pathlib import Path
|
| # Create some artifacts data to preserve
| features = "rooms, zipcode, median_price, school_rating, transport"
| data = {"state": "TX", "Available": 25, "Type": "Detached"}
| with tempfile.TemporaryDirectory() as tmp_dir:
| tmp_dir = Path(tmp_dir)
| with (tmp_dir / "data.json").open("w") as f:
| json.dump(data, f, indent=2)
| with (tmp_dir / "features.json").open("w") as f:
| f.write(features)
|
| # Create a run under the default experiment (whose id is '0'), and log
| # all files in "data" to root artifact_uri/states
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| client.log_artifacts(run.info.run_id, tmp_dir, artifact_path="states")
|
| artifacts = client.list_artifacts(run.info.run_id)
| for artifact in artifacts:
| print(f"artifact: {artifact.path}")
| print(f"is_dir: {artifact.is_dir}")
| client.set_terminated(run.info.run_id)
|
| .. code-block:: text
| :caption: Output
|
| artifact: states
| is_dir: True
|
| log_batch(self, run_id: str, metrics: Sequence[mlflow.entities.metric.Metric] = (), params: Sequence[mlflow.entities.param.Param] = (), tags: Sequence[mlflow.entities.run_tag.RunTag] = (), synchronous: bool | None = None) -> mlflow.utils.async_logging.run_operations.RunOperations | None
| Log multiple metrics, params, and/or tags.
|
| Args:
| run_id: String ID of the run
| metrics: If provided, List of Metric(key, value, timestamp) instances.
| params: If provided, List of Param(key, value) instances.
| tags: If provided, List of RunTag(key, value) instances.
| synchronous: *Experimental* If True, blocks until the metric is logged successfully.
| If False, logs the metric asynchronously and returns a future representing the
| logging operation. If None, read from environment variable
| `MLFLOW_ENABLE_ASYNC_LOGGING`, which defaults to False if not set.
|
| Raises:
| mlflow.MlflowException: If any errors occur.
|
| Returns:
| When `synchronous=True` or None, returns None. When `synchronous=False`, returns an
| :py:class:`mlflow.utils.async_logging.run_operations.RunOperations` instance that
| represents future for logging operation.
|
| .. code-block:: python
| :caption: Example
|
| import time
|
| from mlflow import MlflowClient
| from mlflow.entities import Metric, Param, RunTag
|
|
| def print_run_info(r):
| print(f"run_id: {r.info.run_id}")
| print(f"params: {r.data.params}")
| print(f"metrics: {r.data.metrics}")
| print(f"tags: {r.data.tags}")
| print(f"status: {r.info.status}")
|
|
| # Create MLflow entities and a run under the default experiment (whose id is '0').
| timestamp = int(time.time() * 1000)
| metrics = [Metric("m", 1.5, timestamp, 1)]
| params = [Param("p", "p")]
| tags = [RunTag("t", "t")]
| experiment_id = "0"
| client = MlflowClient()
| run = client.create_run(experiment_id)
|
| # Log entities, terminate the run, and fetch run status
| client.log_batch(run.info.run_id, metrics=metrics, params=params, tags=tags)
| client.set_terminated(run.info.run_id)
| run = client.get_run(run.info.run_id)
| print_run_info(run)
|
| # To log metric in async fashion
| client.log_metric(run.info.run_id, "m", 1.5, synchronous=False)
|
| .. code-block:: text
| :caption: Output
|
| run_id: ef0247fa3205410595acc0f30f620871
| params: {'p': 'p'}
| metrics: {'m': 1.5}
| tags: {'t': 't'}
| status: FINISHED
|
| log_dict(self, run_id: str, dictionary: dict[str, typing.Any], artifact_file: str) -> None
| Log a JSON/YAML-serializable object (e.g. `dict`) as an artifact. The serialization
| format (JSON or YAML) is automatically inferred from the extension of `artifact_file`.
| If the file extension doesn't exist or match any of [".json", ".yml", ".yaml"],
| JSON format is used, and we stringify objects that can't be JSON-serialized.
|
| Args:
| run_id: String ID of the run.
| dictionary: Dictionary to log.
| artifact_file: The run-relative artifact file path in posixpath format to which
| the dictionary is saved (e.g. "dir/data.json").
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| run = client.create_run(experiment_id="0")
| run_id = run.info.run_id
|
| dictionary = {"k": "v"}
|
| # Log a dictionary as a JSON file under the run's root artifact directory
| client.log_dict(run_id, dictionary, "data.json")
|
| # Log a dictionary as a YAML file in a subdirectory of the run's root artifact directory
| client.log_dict(run_id, dictionary, "dir/data.yml")
|
| # If the file extension doesn't exist or match any of [".json", ".yaml", ".yml"],
| # JSON format is used.
| mlflow.log_dict(run_id, dictionary, "data")
| mlflow.log_dict(run_id, dictionary, "data.txt")
|
| log_figure(self, run_id: str, figure: Union[ForwardRef('matplotlib.figure.Figure'), ForwardRef('plotly.graph_objects.Figure')], artifact_file: str, *, save_kwargs: dict[str, typing.Any] | None = None) -> None
| Log a figure as an artifact. The following figure objects are supported:
|
| - `matplotlib.figure.Figure`_
| - `plotly.graph_objects.Figure`_
|
| .. _matplotlib.figure.Figure:
| https://matplotlib.org/api/_as_gen/matplotlib.figure.Figure.html
|
| .. _plotly.graph_objects.Figure:
| https://plotly.com/python-api-reference/generated/plotly.graph_objects.Figure.html
|
| Args:
| run_id: String ID of the run.
| figure: Figure to log.
| artifact_file: The run-relative artifact file path in posixpath format to which
| the figure is saved (e.g. "dir/file.png").
| save_kwargs: Additional keyword arguments passed to the method that saves the figure.
|
| .. code-block:: python
| :caption: Matplotlib Example
|
| import mlflow
| import matplotlib.pyplot as plt
|
| fig, ax = plt.subplots()
| ax.plot([0, 1], [2, 3])
|
| run = client.create_run(experiment_id="0")
| client.log_figure(run.info.run_id, fig, "figure.png")
|
| .. code-block:: python
| :caption: Plotly Example
|
| import mlflow
| from plotly import graph_objects as go
|
| fig = go.Figure(go.Scatter(x=[0, 1], y=[2, 3]))
|
| run = client.create_run(experiment_id="0")
| client.log_figure(run.info.run_id, fig, "figure.html")
|
| log_image(self, run_id: str, image: Union[ForwardRef('numpy.ndarray'), ForwardRef('PIL.Image.Image'), ForwardRef('mlflow.Image')], artifact_file: str | None = None, key: str | None = None, step: int | None = None, timestamp: int | None = None, synchronous: bool | None = None) -> None
| Logs an image in MLflow, supporting two use cases:
|
| 1. Time-stepped image logging:
| Ideal for tracking changes or progressions through iterative processes (e.g.,
| during model training phases).
|
| - Usage: :code:`log_image(image, key=key, step=step, timestamp=timestamp)`
|
| 2. Artifact file image logging:
| Best suited for static image logging where the image is saved directly as a file
| artifact.
|
| - Usage: :code:`log_image(image, artifact_file)`
|
| The following image formats are supported:
| - `numpy.ndarray`_
| - `PIL.Image.Image`_
|
| .. _numpy.ndarray:
| https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html
|
| .. _PIL.Image.Image:
| https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image
|
| - :class:`mlflow.Image`: An MLflow wrapper around PIL image for convenient image
| logging.
|
| Numpy array support
| - data types:
|
| - bool (useful for logging image masks)
| - integer [0, 255]
| - unsigned integer [0, 255]
| - float [0.0, 1.0]
|
| .. warning::
|
| - Out-of-range integer values will raise ValueError.
| - Out-of-range float values will auto-scale with min/max and warn.
|
| - shape (H: height, W: width):
|
| - H x W (Grayscale)
| - H x W x 1 (Grayscale)
| - H x W x 3 (an RGB channel order is assumed)
| - H x W x 4 (an RGBA channel order is assumed)
|
| Args:
| run_id: String ID of run.
| image: The image object to be logged.
| artifact_file: Specifies the path, in POSIX format, where the image
| will be stored as an artifact relative to the run's root directory (for
| example, "dir/image.png"). This parameter is kept for backward compatibility
| and should not be used together with `key`, `step`, or `timestamp`.
| key: Image name for time-stepped image logging. This string may only contain
| alphanumerics, underscores (_), dashes (-), periods (.), spaces ( ), and
| slashes (/).
| step: Integer training step (iteration) at which the image was saved.
| Defaults to 0.
| timestamp: Time when this image was saved. Defaults to the current system time.
| synchronous: *Experimental* If True, blocks until the metric is logged successfully.
| If False, logs the metric asynchronously and returns a future representing the
| logging operation. If None, read from environment variable
| `MLFLOW_ENABLE_ASYNC_LOGGING`, which defaults to False if not set.
|
| .. code-block:: python
| :caption: Time-stepped image logging numpy example
|
| import mlflow
| import numpy as np
|
| image = np.random.randint(0, 256, size=(100, 100, 3), dtype=np.uint8)
| with mlflow.start_run() as run:
| client = mlflow.MlflowClient()
| client.log_image(run.info.run_id, image, key="dogs", step=3)
|
| .. code-block:: python
| :caption: Time-stepped image logging pillow example
|
| import mlflow
| from PIL import Image
|
| image = Image.new("RGB", (100, 100))
| with mlflow.start_run() as run:
| client = mlflow.MlflowClient()
| client.log_image(run.info.run_id, image, key="dogs", step=3)
|
| .. code-block:: python
| :caption: Time-stepped image logging with mlflow.Image example
|
| import mlflow
| from PIL import Image
|
| # Saving an image to retrieve later.
| Image.new("RGB", (100, 100)).save("image.png")
|
| image = mlflow.Image("image.png")
| with mlflow.start_run() as run:
| client = mlflow.MlflowClient()
| client.log_image(run.info.run_id, image, key="dogs", step=3)
|
| .. code-block:: python
| :caption: Legacy artifact file image logging numpy example
|
| import mlflow
| import numpy as np
|
| image = np.random.randint(0, 256, size=(100, 100, 3), dtype=np.uint8)
| with mlflow.start_run() as run:
| client = mlflow.MlflowClient()
| client.log_image(run.info.run_id, image, "image.png")
|
| .. code-block:: python
| :caption: Legacy artifact file image logging pillow example
|
| import mlflow
| from PIL import Image
|
| image = Image.new("RGB", (100, 100))
| with mlflow.start_run() as run:
| client = mlflow.MlflowClient()
| client.log_image(run.info.run_id, image, "image.png")
|
| log_inputs(self, run_id: str, datasets: Optional[Sequence[mlflow.entities.dataset_input.DatasetInput]] = None, models: Optional[Sequence[mlflow.entities.logged_model_input.LoggedModelInput]] = None) -> None
| Log one or more dataset inputs to a run.
|
| Args:
| run_id: String ID of the run.
| datasets: List of :py:class:`mlflow.entities.DatasetInput` instances to log.
| models: List of :py:class:`mlflow.entities.LoggedModelInput` instances to log.
|
| Raises:
| mlflow.MlflowException: If any errors occur.
|
| log_metric(self, run_id: str, key: str, value: float, timestamp: int | None = None, step: int | None = None, synchronous: bool | None = None, dataset_name: str | None = None, dataset_digest: str | None = None, model_id: str | None = None) -> mlflow.utils.async_logging.run_operations.RunOperations | None
| Log a metric against the run ID.
|
| Args:
| run_id: The run id to which the metric should be logged.
| key: Metric name. This string may only contain alphanumerics, underscores
| (_), dashes (-), periods (.), spaces ( ), and slashes (/).
| All backend stores will support keys up to length 250, but some may
| support larger keys.
| value: Metric value. Note that some special values such
| as +/- Infinity may be replaced by other values depending on the store. For
| example, the SQLAlchemy store replaces +/- Inf with max / min float values.
| All backend stores will support values up to length 5000, but some
| may support larger values.
| timestamp: Time when this metric was calculated. Defaults to the current system time.
| step: Integer training step (iteration) at which was the metric calculated.
| Defaults to 0.
| synchronous: *Experimental* If True, blocks until the metric is logged successfully.
| If False, logs the metric asynchronously and returns a future representing the
| logging operation. If None, read from environment variable
| `MLFLOW_ENABLE_ASYNC_LOGGING`, which defaults to False if not set.
| dataset_name: The name of the dataset associated with the metric. If specified,
| ``dataset_digest`` must also be provided.
| dataset_digest: The digest of the dataset associated with the metric. If specified,
| ``dataset_name`` must also be provided.
| model_id: The ID of the model associated with the metric. If not specified, use the
| current active model ID set by :py:func:`mlflow.set_active_model`.
|
| Returns:
| When `synchronous=True` or None, returns None. When `synchronous=False`, returns an
| :py:class:`mlflow.utils.async_logging.run_operations.RunOperations` instance that
| represents future for logging operation.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_run_info(r):
| print(f"run_id: {r.info.run_id}")
| print(f"metrics: {r.data.metrics}")
| print(f"status: {r.info.status}")
|
|
| # Create a run under the default experiment (whose id is '0').
| # Since these are low-level CRUD operations, this method will create a run.
| # To end the run, you'll have to explicitly end it.
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| print_run_info(run)
| print("--")
|
| # Log the metric. Unlike mlflow.log_metric this method
| # does not start a run if one does not exist. It will log
| # the metric for the run id in the backend store.
| client.log_metric(run.info.run_id, "m", 1.5)
| client.set_terminated(run.info.run_id)
| run = client.get_run(run.info.run_id)
| print_run_info(run)
|
| # To log metric in async fashion
| client.log_metric(run.info.run_id, "m", 1.5, synchronous=False)
|
| .. code-block:: text
| :caption: Output
|
| run_id: 95e79843cb2c463187043d9065185e24
| metrics: {}
| status: RUNNING
| --
| run_id: 95e79843cb2c463187043d9065185e24
| metrics: {'m': 1.5}
| status: FINISHED
|
| log_model_artifact(self, model_id: str, local_path: str) -> None
| Upload an artifact to the specified logged model.
|
| Args:
| model_id: ID of the model.
| local_path: Local path to the artifact to upload.
|
| Returns:
| None
|
| log_model_artifacts(self, model_id: str, local_dir: str) -> None
| Upload a set of artifacts to the specified logged model.
|
| Args:
| model_id: ID of the model.
| local_dir: Local directory containing the artifacts to upload.
|
| Returns:
| None
|
| log_model_params(self, model_id: str, params: dict[str, str]) -> None
| Log parameters for a logged model.
|
| Args:
| model_id: ID of the model to log parameters for.
| params: Dictionary of parameters to log.
|
| Returns:
| None
|
| log_outputs(self, run_id: str, models: list[mlflow.entities.logged_model_output.LoggedModelOutput])
|
| log_param(self, run_id: str, key: str, value: Any, synchronous: bool | None = None) -> Any
| Log a parameter (e.g. model hyperparameter) against the run ID.
|
| Args:
| run_id: The run id to which the param should be logged.
| key: Parameter name. This string may only contain alphanumerics, underscores
| (_), dashes (-), periods (.), spaces ( ), and slashes (/).
| All backend stores support keys up to length 250, but some may
| support larger keys.
| value: Parameter value, but will be string-ified if not.
| All built-in backend stores support values up to length 6000, but some
| may support larger values.
| synchronous: *Experimental* If True, blocks until the metric is logged successfully.
| If False, logs the metric asynchronously and returns a future representing the
| logging operation. If None, read from environment variable
| `MLFLOW_ENABLE_ASYNC_LOGGING`, which defaults to False if not set.
|
| Returns:
| When `synchronous=True` or None, returns parameter value. When `synchronous=False`,
| returns an :py:class:`mlflow.utils.async_logging.run_operations.RunOperations`
| instance that represents future for logging operation.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_run_info(r):
| print(f"run_id: {r.info.run_id}")
| print(f"params: {r.data.params}")
| print(f"status: {r.info.status}")
|
|
| # Create a run under the default experiment (whose id is '0').
| # Since these are low-level CRUD operations, this method will create a run.
| # To end the run, you'll have to explicitly end it.
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| print_run_info(run)
| print("--")
| # Log the parameter. Unlike mlflow.log_param this method
| # does not start a run if one does not exist. It will log
| # the parameter in the backend store
| p_value = client.log_param(run.info.run_id, "p", 1)
| assert p_value == 1
| client.set_terminated(run.info.run_id)
| run = client.get_run(run.info.run_id)
| print_run_info(run)
|
| .. code-block:: text
| :caption: Output
|
| run_id: e649e49c7b504be48ee3ae33c0e76c93
| params: {}
| status: RUNNING
| --
| run_id: e649e49c7b504be48ee3ae33c0e76c93
| params: {'p': '1'}
| status: FINISHED
|
| log_stream(self, run_id: str, stream: io.BufferedIOBase | io.RawIOBase, artifact_file: str) -> None
| .. Note:: Experimental: This function may change or be removed in a future release without warning.
|
|
| Log a binary file-like object (e.g., ``io.BytesIO``) as an artifact.
|
| Args:
| run_id: String ID of the run.
| stream: A binary file-like object supporting ``.read()`` method
| (e.g., ``io.BytesIO``).
| artifact_file: The run-relative artifact file path in posixpath format to which
| the stream content is saved (e.g. "dir/file.bin").
|
| .. code-block:: python
| :caption: Example
|
| import io
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| run = client.create_run(experiment_id="0")
|
| # Log a BytesIO stream
| bytes_stream = io.BytesIO(b"binary content")
| client.log_stream(run.info.run_id, bytes_stream, "binary_file.bin")
|
| log_table(self, run_id: str, data: Union[dict[str, Any], ForwardRef('pandas.DataFrame')], artifact_file: str) -> None
| Log a table to MLflow Tracking as a JSON artifact. If the artifact_file already exists
| in the run, the data would be appended to the existing artifact_file.
|
| Args:
| run_id: String ID of the run.
| data: Dictionary or pandas.DataFrame to log.
| artifact_file: The run-relative artifact file path in posixpath format to which
| the table is saved (e.g. "dir/file.json").
|
| .. code-block:: python
| :test:
| :caption: Dictionary Example
|
| import mlflow
| from mlflow import MlflowClient
|
| table_dict = {
| "inputs": ["What is MLflow?", "What is Databricks?"],
| "outputs": ["MLflow is ...", "Databricks is ..."],
| "toxicity": [0.0, 0.0],
| }
| with mlflow.start_run() as run:
| client = MlflowClient()
| client.log_table(
| run.info.run_id, data=table_dict, artifact_file="qabot_eval_results.json"
| )
|
| .. code-block:: python
| :test:
| :caption: Pandas DF Example
|
| import mlflow
| import pandas as pd
| from mlflow import MlflowClient
|
| table_dict = {
| "inputs": ["What is MLflow?", "What is Databricks?"],
| "outputs": ["MLflow is ...", "Databricks is ..."],
| "toxicity": [0.0, 0.0],
| }
| df = pd.DataFrame.from_dict(table_dict)
| with mlflow.start_run() as run:
| client = MlflowClient()
| client.log_table(run.info.run_id, data=df, artifact_file="qabot_eval_results.json")
|
| .. code-block:: python
| :test:
| :caption: Image Column Example
|
| import mlflow
| import pandas as pd
| from mlflow import MlflowClient
|
| image = mlflow.Image([[1, 2, 3]])
| table_dict = {
| "inputs": ["Show me a dog", "Show me a cat"],
| "outputs": [image, image],
| }
| df = pd.DataFrame.from_dict(table_dict)
| with mlflow.start_run() as run:
| client = MlflowClient()
| client.log_table(run.info.run_id, data=df, artifact_file="image_gen.json")
|
| log_text(self, run_id: str, text: str, artifact_file: str) -> None
| Log text as an artifact.
|
| Args:
| run_id: String ID of the run.
| text: String containing text to log.
| artifact_file: The run-relative artifact file path in posixpath format to which
| the text is saved (e.g. "dir/file.txt").
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| run = client.create_run(experiment_id="0")
|
| # Log text to a file under the run's root artifact directory
| client.log_text(run.info.run_id, "text1", "file1.txt")
|
| # Log text in a subdirectory of the run's root artifact directory
| client.log_text(run.info.run_id, "text2", "dir/file2.txt")
|
| # Log HTML text
| client.log_text(run.info.run_id, "<h1>header</h1>", "index.html")
|
| parse_prompt_uri(self, uri: str) -> tuple[str, str]
| Parse prompt URI into prompt name and prompt version.
| - 'prompts:/<name>/<version>' -> ('<name>', '<version>')
| - 'prompts:/<name>@<alias>' -> ('<name>', '<version>')
|
| This method reuses the existing model URI parsing logic with prompts prefix.
|
| refresh_mcp_server_version_tools(self, name: str, version: str, mcp_server_access_headers: Optional[Mapping[str, str]] = None, dry_run: bool = False) -> mlflow.entities.mcp_server_version.MCPServerVersion
|
| register_prompt(self, name: str, template: str | list[dict[str, typing.Any]], commit_message: str | None = None, tags: dict[str, str] | None = None, response_format: type[pydantic.main.BaseModel] | dict[str, typing.Any] | None = None, model_config: 'PromptModelConfig | dict[str, Any] | None' = None) -> mlflow.entities.model_registry.prompt_version.PromptVersion
| Register a new :py:class:`Prompt <mlflow.entities.Prompt>` in the MLflow Prompt Registry.
|
| A :py:class:`Prompt <mlflow.entities.Prompt>` is a pair of name
| and template content at minimum. With MLflow Prompt Registry, you can create, manage,
| and version control prompts with the MLflow's robust model tracking framework.
|
| If there is no registered prompt with the given name, a new prompt will be created.
| Otherwise, a new version of the existing prompt will be created.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
| from pydantic import BaseModel
|
| # Your prompt registry URI
| client = MlflowClient(registry_uri="sqlite:///prompt_registry.db")
|
| # Register a text prompt
| client.register_prompt(
| name="greeting_prompt",
| template="Respond to the user's message as a {{style}} AI.",
| response_format={"type": "string", "description": "A friendly response"},
| )
|
| # Register a chat prompt with multiple messages
| client.register_prompt(
| name="assistant_prompt",
| template=[
| {"role": "system", "content": "You are a helpful {{style}} assistant."},
| {"role": "user", "content": "{{question}}"},
| ],
| response_format={"type": "object", "properties": {"answer": {"type": "string"}}},
| )
|
| # Load the prompt from the registry
| prompt = client.load_prompt("greeting_prompt")
|
| # Use the prompt in your application
| import openai
|
| openai_client = openai.OpenAI()
| openai_client.chat.completion.create(
| model="gpt-4o-mini",
| messages=[
| {"role": "system", "content": prompt.format(style="friendly")},
| {"role": "user", "content": "Hello, how are you?"},
| ],
| )
|
| # Update the prompt with a new version
| prompt = client.register_prompt(
| name="greeting_prompt",
| template="Respond to the user's message as a {{style}} AI. {{greeting}}",
| commit_message="Add a greeting to the prompt.",
| tags={"author": "Bob"},
| )
|
| Args:
| name: The name of the prompt.
| template: The template content of the prompt. Can be either:
|
| - A string containing text with variables enclosed in double curly braces,
| e.g. {{variable}}, which will be replaced with actual values by the `format`
| method.
| - A list of dictionaries representing chat messages, where each message has
| 'role' and 'content' keys (e.g., [{"role": "user", "content": "Hello {{name}}"}])
|
| commit_message: A message describing the changes made to the prompt, similar to a
| Git commit message. Optional.
| tags: A dictionary of tags for the prompt.
| These tags are stored on the prompt version and written to prompt-level metadata.
| For OSS, later ``register_prompt()`` calls can overwrite the same keys at the
| prompt level. Optional.
| response_format: Optional Pydantic class or dictionary defining the expected response
| structure. This can be used to specify the schema for structured outputs from LLM
| calls.
| model_config: Optional PromptModelConfig instance or dictionary containing
| model-specific configuration like model_name, temperature, max_tokens, etc.
| Using PromptModelConfig provides validation and type safety.
|
| Returns:
| A :py:class:`Prompt <mlflow.entities.Prompt>` object that was created.
|
| remove_dataset_from_experiments(self, dataset_id: str, experiment_ids: list[str]) -> mlflow.entities.evaluation_dataset.EvaluationDataset
| Remove a dataset from experiments.
|
| This operation is idempotent - removing non-existent associations will not raise errors.
|
| Args:
| dataset_id: The ID of the dataset to update.
| experiment_ids: List of experiment IDs to remove association from.
|
| Returns:
| The updated EvaluationDataset with removed experiment associations.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Remove dataset from experiments
| dataset = client.remove_dataset_from_experiments(
| dataset_id="d-abc123", experiment_ids=["2", "3"]
| )
| print(f"Dataset now associated with {len(dataset.experiment_ids)} experiments")
|
| rename_experiment(self, experiment_id: str, new_name: str) -> None
| Update an experiment's name. The new name must be unique.
|
| Args:
| experiment_id: The experiment ID returned from ``create_experiment``.
| new_name: The new name for the experiment.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_experiment_info(experiment):
| print(f"Name: {experiment.name}")
| print(f"Experiment_id: {experiment.experiment_id}")
| print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
|
|
| # Create an experiment with a name that is unique and case sensitive
| client = MlflowClient()
| experiment_id = client.create_experiment("Social NLP Experiments")
|
| # Fetch experiment metadata information
| experiment = client.get_experiment(experiment_id)
| print_experiment_info(experiment)
| print("--")
|
| # Rename and fetch experiment metadata information
| client.rename_experiment(experiment_id, "Social Media NLP Experiments")
| experiment = client.get_experiment(experiment_id)
| print_experiment_info(experiment)
|
| .. code-block:: text
| :caption: Output
|
| Name: Social NLP Experiments
| Experiment_id: 1
| Lifecycle_stage: active
| --
| Name: Social Media NLP Experiments
| Experiment_id: 1
| Lifecycle_stage: active
|
| rename_registered_model(self, name: str, new_name: str) -> mlflow.entities.model_registry.registered_model.RegisteredModel
| Update registered model name.
|
| Args:
| name: Name of the registered model to update.
| new_name: New proposed name for the registered model.
|
| Returns:
| A single updated :py:class:`mlflow.entities.model_registry.RegisteredModel` object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
|
| def print_registered_model_info(rm):
| print(f"name: {rm.name}")
| print(f"tags: {rm.tags}")
| print(f"description: {rm.description}")
|
|
| name = "SocialTextAnalyzer"
| tags = {"nlp.framework": "Spark NLP"}
| desc = "This sentiment analysis model classifies the tone-happy, sad, angry."
|
| # create a new registered model name
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| client = MlflowClient()
| client.create_registered_model(name, tags, desc)
| print_registered_model_info(client.get_registered_model(name))
| print("--")
|
| # rename the model
| new_name = "SocialMediaTextAnalyzer"
| client.rename_registered_model(name, new_name)
| print_registered_model_info(client.get_registered_model(new_name))
|
| .. code-block:: text
| :caption: Output
|
| name: SocialTextAnalyzer
| tags: {'nlp.framework': 'Spark NLP'}
| description: This sentiment analysis model classifies the tone-happy, sad, angry.
| --
| name: SocialMediaTextAnalyzer
| tags: {'nlp.framework': 'Spark NLP'}
| description: This sentiment analysis model classifies the tone-happy, sad, angry.
|
| restore_experiment(self, experiment_id: str) -> None
| Restore a deleted experiment unless permanently deleted.
|
| Args:
| experiment_id: The experiment ID returned from ``create_experiment``.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_experiment_info(experiment):
| print(f"Name: {experiment.name}")
| print(f"Experiment Id: {experiment.experiment_id}")
| print(f"Lifecycle_stage: {experiment.lifecycle_stage}")
|
|
| # Create and delete an experiment
| client = MlflowClient()
| experiment_id = client.create_experiment("New Experiment")
| client.delete_experiment(experiment_id)
|
| # Examine the deleted experiment details.
| experiment = client.get_experiment(experiment_id)
| print_experiment_info(experiment)
| print("--")
|
| # Restore the experiment and fetch its info
| client.restore_experiment(experiment_id)
| experiment = client.get_experiment(experiment_id)
| print_experiment_info(experiment)
|
| .. code-block:: text
| :caption: Output
|
| Name: New Experiment
| Experiment Id: 1
| Lifecycle_stage: deleted
| --
| Name: New Experiment
| Experiment Id: 1
| Lifecycle_stage: active
|
| restore_run(self, run_id: str) -> None
| Restores a deleted run with the given ID.
|
| Args:
| run_id: The unique run id to restore.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
| # Create a run under the default experiment (whose id is '0').
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| run_id = run.info.run_id
| print(f"run_id: {run_id}; lifecycle_stage: {run.info.lifecycle_stage}")
| client.delete_run(run_id)
| del_run = client.get_run(run_id)
| print(f"run_id: {run_id}; lifecycle_stage: {del_run.info.lifecycle_stage}")
| client.restore_run(run_id)
| rest_run = client.get_run(run_id)
| print(f"run_id: {run_id}; lifecycle_stage: {rest_run.info.lifecycle_stage}")
|
| .. code-block:: text
| :caption: Output
|
| run_id: 7bc59754d7e74534a7917d62f2873ac0; lifecycle_stage: active
| run_id: 7bc59754d7e74534a7917d62f2873ac0; lifecycle_stage: deleted
| run_id: 7bc59754d7e74534a7917d62f2873ac0; lifecycle_stage: active
|
| search_datasets(self, experiment_ids: list[str] | None = None, filter_string: str | None = None, max_results: int = 50, order_by: list[str] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.evaluation_dataset.EvaluationDataset]
| Search for datasets.
|
| Args:
| experiment_ids: List of experiment IDs to filter by.
| filter_string: A filter string to apply to the search.
| max_results: Maximum number of results to return. Defaults to 50.
| order_by: List of columns to order by.
| page_token: Token for the next page of results.
|
| Returns:
| A PagedList of EvaluationDataset objects.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Search for datasets in specific experiments
| datasets = client.search_datasets(
| experiment_ids=["exp1", "exp2"], filter_string="name LIKE 'qa_%'", max_results=10
| )
|
| # Get next page if available
| if datasets.token:
| next_page = client.search_datasets(
| experiment_ids=["exp1", "exp2"], page_token=datasets.token
| )
|
| search_experiments(self, view_type: int = 1, max_results: int | None = 1000, filter_string: str | None = None, order_by: list[str] | None = None, page_token=None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.experiment.Experiment]
| Search for experiments that match the specified search query.
|
| Args:
| view_type: One of enum values ``ACTIVE_ONLY``, ``DELETED_ONLY``, or ``ALL``
| defined in :py:class:`mlflow.entities.ViewType`.
| max_results: Maximum number of experiments desired. Certain server backend may apply
| its own limit.
| filter_string: Filter query string (e.g., ``"name = 'my_experiment'"``), defaults to
| searching for all experiments. The following identifiers, comparators, and logical
| operators are supported.
|
| Identifiers
| - ``name``: Experiment name
| - ``creation_time``: Experiment creation time
| - ``last_update_time``: Experiment last update time
| - ``tags.<tag_key>``: Experiment tag. If ``tag_key`` contains
| spaces, it must be wrapped with backticks (e.g., ``"tags.`extra key`"``).
|
| Comparators for string attributes and tags
| - ``=``: Equal to
| - ``!=``: Not equal to
| - ``LIKE``: Case-sensitive pattern match
| - ``ILIKE``: Case-insensitive pattern match
|
| Comparators for numeric attributes
| - ``=``: Equal to
| - ``!=``: Not equal to
| - ``<``: Less than
| - ``<=``: Less than or equal to
| - ``>``: Greater than
| - ``>=``: Greater than or equal to
|
| Logical operators
| - ``AND``: Combines two sub-queries and returns True if both of them are True.
|
| order_by: List of columns to order by. The ``order_by`` column can contain an optional
| ``DESC`` or ``ASC`` value (e.g., ``"name DESC"``). The default ordering is ``ASC``,
| so ``"name"`` is equivalent to ``"name ASC"``. If unspecified, defaults to
| ``["last_update_time DESC"]``, which lists experiments updated most recently first.
| The following fields are supported:
|
| - ``experiment_id``: Experiment ID
| - ``name``: Experiment name
| - ``creation_time``: Experiment creation time
| - ``last_update_time``: Experiment last update time
|
| page_token: Token specifying the next page of results. It should be obtained from
| a ``search_experiments`` call.
|
| Returns:
| A :py:class:`PagedList <mlflow.store.entities.PagedList>` of
| :py:class:`Experiment <mlflow.entities.Experiment>` objects. The pagination token
| for the next page can be obtained via the ``token`` attribute of the object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
|
|
| def assert_experiment_names_equal(experiments, expected_names):
| actual_names = [e.name for e in experiments if e.name != "Default"]
| assert actual_names == expected_names, (actual_names, expected_names)
|
|
| mlflow.set_tracking_uri("sqlite:///:memory:")
| client = mlflow.MlflowClient()
|
| # Create experiments
| for name, tags in [
| ("a", None),
| ("b", None),
| ("ab", {"k": "v"}),
| ("bb", {"k": "V"}),
| ]:
| client.create_experiment(name, tags=tags)
|
| # Search for experiments with name "a"
| experiments = client.search_experiments(filter_string="name = 'a'")
| assert_experiment_names_equal(experiments, ["a"])
|
| # Search for experiments with name starting with "a"
| experiments = client.search_experiments(filter_string="name LIKE 'a%'")
| assert_experiment_names_equal(experiments, ["ab", "a"])
|
| # Search for experiments with tag key "k" and value ending with "v" or "V"
| experiments = client.search_experiments(filter_string="tags.k ILIKE '%v'")
| assert_experiment_names_equal(experiments, ["bb", "ab"])
|
| # Search for experiments with name ending with "b" and tag {"k": "v"}
| experiments = client.search_experiments(filter_string="name LIKE '%b' AND tags.k = 'v'")
| assert_experiment_names_equal(experiments, ["ab"])
|
| # Sort experiments by name in ascending order
| experiments = client.search_experiments(order_by=["name"])
| assert_experiment_names_equal(experiments, ["a", "ab", "b", "bb"])
|
| # Sort experiments by ID in descending order
| experiments = client.search_experiments(order_by=["experiment_id DESC"])
| assert_experiment_names_equal(experiments, ["bb", "ab", "b", "a"])
|
| search_logged_models(self, experiment_ids: list[str], filter_string: str | None = None, datasets: list[dict[str, typing.Any]] | None = None, max_results: int | None = None, order_by: list[dict[str, typing.Any]] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.logged_model.LoggedModel]
| Search for logged models that match the specified search criteria.
|
| Args:
| experiment_ids: List of experiment ids to scope the search.
| filter_string: A SQL-like filter string to parse. The filter string syntax supports:
|
| - Entity specification:
| - attributes: `attribute_name` (default if no prefix is specified)
| - metrics: `metrics.metric_name`
| - parameters: `params.param_name`
| - tags: `tags.tag_name`
| - Comparison operators:
| - For numeric entities (metrics and numeric attributes): <, <=, >, >=, =, !=
| - For string entities (params, tags, string attributes): =, !=, IN, NOT IN
| - Multiple conditions can be joined with 'AND'
| - String values must be enclosed in single quotes
|
| Example filter strings:
| - `creation_time > 100`
| - `metrics.rmse > 0.5 AND params.model_type = 'rf'`
| - `tags.release IN ('v1.0', 'v1.1')`
| - `params.optimizer != 'adam' AND metrics.accuracy >= 0.9`
| datasets: List of dictionaries to specify datasets on which to apply metrics filters
| For example, a filter string with `metrics.accuracy > 0.9` and dataset with name
| "test_dataset" means we will return all logged models with accuracy > 0.9 on the
| test_dataset. Metric values from ANY dataset matching the criteria are considered.
| If no datasets are specified, then metrics across all datasets are considered in
| the filter. The following fields are supported:
|
| dataset_name (str):
| Required. Name of the dataset.
| dataset_digest (str):
| Optional. Digest of the dataset.
| max_results: Maximum number of logged models desired.
| order_by: List of dictionaries to specify the ordering of the search results.
| The following fields are supported:
|
| field_name (str):
| Required. Name of the field to order by, e.g. "metrics.accuracy".
| ascending (bool):
| Optional. Whether the order is ascending or not.
| dataset_name (str):
| Optional. If ``field_name`` refers to a metric, this field
| specifies the name of the dataset associated with the metric. Only metrics
| associated with the specified dataset name will be considered for ordering.
| This field may only be set if ``field_name`` refers to a metric.
| dataset_digest (str):
| Optional. If ``field_name`` refers to a metric, this field
| specifies the digest of the dataset associated with the metric. Only metrics
| associated with the specified dataset name and digest will be considered for
| ordering. This field may only be set if ``dataset_name`` is also set.
| page_token: Token specifying the next page of results.
|
| Returns:
| A :py:class:`PagedList <mlflow.store.entities.PagedList>` of
| :py:class:`LoggedModel <mlflow.entities.LoggedModel>` objects.
|
| search_mcp_access_endpoints(self, server_name: str | None = None, server_version: str | None = None, server_alias: str | None = None, filter_string: str | None = None, max_results: int = 1000, order_by: list[str] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.mcp_access_endpoint.MCPAccessEndpoint]
|
| search_mcp_server_versions(self, name: str, filter_string: str | None = None, max_results: int = 1000, order_by: list[str] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.mcp_server_version.MCPServerVersion]
|
| search_mcp_servers(self, filter_string: str | None = None, max_results: int = 1000, order_by: list[str] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.mcp_server.MCPServer]
|
| search_model_versions(self, filter_string: str | None = None, max_results: int = 10000, order_by: list[str] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.model_registry.model_version.ModelVersion]
| Search for model versions in backend that satisfy the filter criteria.
|
| .. warning:
| The model version search results may not have aliases populated for performance reasons.
|
| Args:
| filter_string: Filter query string
| (e.g., ``"name = 'a_model_name' and tag.key = 'value1'"``),
| defaults to searching for all model versions. The following identifiers,
| comparators, and logical operators are supported.
|
| Identifiers
| - ``name``: model name.
| - ``source_path``: model version source path.
| - ``run_id``: The id of the mlflow run that generates the model version.
| - ``tags.<tag_key>``: model version tag. If ``tag_key`` contains spaces, it must
| be wrapped with backticks (e.g., ``"tags.`extra key`"``).
|
| Comparators
| - ``=``: Equal to.
| - ``!=``: Not equal to.
| - ``LIKE``: Case-sensitive pattern match.
| - ``ILIKE``: Case-insensitive pattern match.
| - ``IN``: In a value list. Only ``run_id`` identifier supports ``IN`` comparator.
|
| Logical operators
| - ``AND``: Combines two sub-queries and returns True if both of them are True.
|
| max_results: Maximum number of model versions desired.
| order_by: List of column names with ASC|DESC annotation, to be used for ordering
| matching search results.
| page_token: Token specifying the next page of results. It should be obtained from
| a ``search_model_versions`` call.
|
| Returns:
| A PagedList of :py:class:`mlflow.entities.model_registry.ModelVersion`
| objects that satisfy the search expressions. The pagination token for the next
| page can be obtained via the ``token`` attribute of the object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Get all versions of the model filtered by name
| model_name = "CordobaWeatherForecastModel"
| filter_string = f"name='{model_name}'"
| results = client.search_model_versions(filter_string)
| print("-" * 80)
| for res in results:
| print(f"name={res.name}; run_id={res.run_id}; version={res.version}")
|
| # Get the version of the model filtered by run_id
| run_id = "e14afa2f47a040728060c1699968fd43"
| filter_string = f"run_id='{run_id}'"
| results = client.search_model_versions(filter_string)
| print("-" * 80)
| for res in results:
| print(f"name={res.name}; run_id={res.run_id}; version={res.version}")
|
| .. code-block:: text
| :caption: Output
|
| ------------------------------------------------------------------------------------
| name=CordobaWeatherForecastModel; run_id=eaef868ee3d14d10b4299c4c81ba8814; version=1
| name=CordobaWeatherForecastModel; run_id=e14afa2f47a040728060c1699968fd43; version=2
| ------------------------------------------------------------------------------------
| name=CordobaWeatherForecastModel; run_id=e14afa2f47a040728060c1699968fd43; version=2
|
| search_prompt_versions(self, name: str, max_results: int | None = None, page_token: str | None = None)
| Search prompt versions for a given prompt name.
|
| Args:
| name: Name of the prompt to search versions for.
| max_results: Maximum number of versions to return.
| page_token: Token for pagination.
|
| Returns:
| A :py:class:`PagedList <mlflow.store.entities.PagedList>` of
| :py:class:`~mlflow.entities.model_registry.PromptVersion` objects.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| versions = client.search_prompt_versions("my_prompt", max_results=10)
| for version in versions:
| print(f"Version {version.version}: {version.template}")
|
| search_prompts(self, filter_string: str | None = None, max_results: int = 1000, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.model_registry.prompt.Prompt]
| Search for prompts in the MLflow Prompt Registry.
|
| This call returns prompt metadata for prompts that have been marked
| as prompts (i.e. tagged with `mlflow.prompt.is_prompt=true`). We can
| further restrict results via a standard registry filter expression.
|
| Args:
| filter_string (Optional[str]):
| An additional registry-search expression to apply (e.g.
| `"name LIKE 'my_prompt%'"`). For Unity Catalog registries, must include
| catalog and schema: "catalog = 'catalog_name' AND schema = 'schema_name'".
| max_results (int):
| The maximum number of prompts to return in one page. Defaults
| to `SEARCH_MAX_RESULTS_DEFAULT` (typically 1 000).
| page_token (Optional[str]):
| A pagination token from a previous `search_prompts` call; use this
| to retrieve the next page of results. Defaults to `None`.
|
| Returns:
| A pageable list of :py:class:`Prompt <mlflow.entities.Prompt>` objects
| representing prompt metadata:
|
| - name: The prompt name
| - description: The prompt description
| - tags: Prompt-level tags
| - creation_timestamp: When the prompt was created
|
| To get the actual prompt template content,
| use get_prompt_version() with a specific version:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| # Your prompt registry URI
| client = MlflowClient(registry_uri="sqlite:///prompt_registry.db")
|
| # Search for prompts
| prompts = client.search_prompts(filter_string="name LIKE 'greeting%'")
|
| # Get prompts by experiment
| prompts = client.search_prompts(filter_string='experiment_id = "1"')
|
| # Get specific version content
| for prompt in prompts:
| prompt_version = client.get_prompt_version(prompt.name, version="1")
| print(f"Template: {prompt_version.template}")
|
| Inspect the returned object's `.token` attribute to fetch subsequent pages.
|
| search_registered_models(self, filter_string: str | None = None, max_results: int = 100, order_by: list[str] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.model_registry.registered_model.RegisteredModel]
| Search for registered models in backend that satisfy the filter criteria.
|
| Args:
| filter_string: Filter query string (e.g., "name = 'a_model_name' and tag.key =
| 'value1'"), defaults to searching for all registered models. The following
| identifiers, comparators, and logical operators are supported.
|
| Identifiers
| - ``name``: registered model name.
| - ``tags.<tag_key>``: registered model tag. If ``tag_key`` contains spaces, it
| must be wrapped with backticks (e.g., "tags.`extra key`").
|
| Comparators
| - ``=``: Equal to.
| - ``!=``: Not equal to.
| - ``LIKE``: Case-sensitive pattern match.
| - ``ILIKE``: Case-insensitive pattern match.
|
| Logical operators
| - ``AND``: Combines two sub-queries and returns True if both of them are True.
|
| max_results: Maximum number of registered models desired.
| order_by: List of column names with ASC|DESC annotation, to be used for ordering
| matching search results.
| page_token: Token specifying the next page of results. It should be obtained from
| a ``search_registered_models`` call.
|
| Returns:
| A PagedList of :py:class:`mlflow.entities.model_registry.RegisteredModel` objects
| that satisfy the search expressions. The pagination token for the next page can be
| obtained via the ``token`` attribute of the object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Get search results filtered by the registered model name
| model_name = "CordobaWeatherForecastModel"
| filter_string = f"name='{model_name}'"
| results = client.search_registered_models(filter_string=filter_string)
| print("-" * 80)
| for res in results:
| for mv in res.latest_versions:
| print(f"name={mv.name}; run_id={mv.run_id}; version={mv.version}")
|
| # Get search results filtered by the registered model name that matches
| # prefix pattern
| filter_string = "name LIKE 'Boston%'"
| results = client.search_registered_models(filter_string=filter_string)
| print("-" * 80)
| for res in results:
| for mv in res.latest_versions:
| print(f"name={mv.name}; run_id={mv.run_id}; version={mv.version}")
|
| # Get all registered models and order them by ascending order of the names
| results = client.search_registered_models(order_by=["name ASC"])
| print("-" * 80)
| for res in results:
| for mv in res.latest_versions:
| print(f"name={mv.name}; run_id={mv.run_id}; version={mv.version}")
|
| .. code-block:: text
| :caption: Output
|
| ------------------------------------------------------------------------------------
| name=CordobaWeatherForecastModel; run_id=eaef868ee3d14d10b4299c4c81ba8814; version=1
| name=CordobaWeatherForecastModel; run_id=e14afa2f47a040728060c1699968fd43; version=2
| ------------------------------------------------------------------------------------
| name=BostonWeatherForecastModel; run_id=ddc51b9407a54b2bb795c8d680e63ff6; version=1
| name=BostonWeatherForecastModel; run_id=48ac94350fba40639a993e1b3d4c185d; version=2
| -----------------------------------------------------------------------------------
| name=AzureWeatherForecastModel; run_id=5fcec6c4f1c947fc9295fef3fa21e52d; version=1
| name=AzureWeatherForecastModel; run_id=8198cb997692417abcdeb62e99052260; version=3
| name=BostonWeatherForecastModel; run_id=ddc51b9407a54b2bb795c8d680e63ff6; version=1
| name=BostonWeatherForecastModel; run_id=48ac94350fba40639a993e1b3d4c185d; version=2
| name=CordobaWeatherForecastModel; run_id=eaef868ee3d14d10b4299c4c81ba8814; version=1
| name=CordobaWeatherForecastModel; run_id=e14afa2f47a040728060c1699968fd43; version=2
|
| search_runs(self, experiment_ids: list[str], filter_string: str = '', run_view_type: int = 1, max_results: int = 1000, order_by: list[str] | None = None, page_token: str | None = None) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.run.Run]
| Search for Runs that fit the specified criteria.
|
| Args:
| experiment_ids: List of experiment IDs, or a single int or string id.
| filter_string: Filter query string, defaults to searching all runs.
| run_view_type: one of enum values ACTIVE_ONLY, DELETED_ONLY, or ALL runs
| defined in :py:class:`mlflow.entities.ViewType`.
| max_results: Maximum number of runs desired.
| order_by: List of columns to order by (e.g., "metrics.rmse"). The ``order_by`` column
| can contain an optional ``DESC`` or ``ASC`` value. The default is ``ASC``.
| The default ordering is to sort by ``start_time DESC``, then ``run_id``.
| page_token: Token specifying the next page of results. It should be obtained from
| a ``search_runs`` call.
|
| Returns:
| A :py:class:`PagedList <mlflow.store.entities.PagedList>` of
| :py:class:`Run <mlflow.entities.Run>` objects that satisfy the search expressions.
| If the underlying tracking store supports pagination, the token for the next page may
| be obtained via the ``token`` attribute of the returned object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
| from mlflow.entities import ViewType
|
|
| def print_run_info(runs):
| for r in runs:
| print(f"run_id: {r.info.run_id}")
| print(f"lifecycle_stage: {r.info.lifecycle_stage}")
| print(f"metrics: {r.data.metrics}")
| # Exclude mlflow system tags
| tags = {k: v for k, v in r.data.tags.items() if not k.startswith("mlflow.")}
| print(f"tags: {tags}")
|
|
| # Create an experiment and log two runs with metrics and tags under the experiment
| experiment_id = mlflow.create_experiment("Social NLP Experiments")
| with mlflow.start_run(experiment_id=experiment_id) as run:
| mlflow.log_metric("m", 1.55)
| mlflow.set_tag("s.release", "1.1.0-RC")
| with mlflow.start_run(experiment_id=experiment_id):
| mlflow.log_metric("m", 2.50)
| mlflow.set_tag("s.release", "1.2.0-GA")
| # Search all runs under experiment id and order them by
| # descending value of the metric 'm'
| client = MlflowClient()
| runs = client.search_runs(experiment_id, order_by=["metrics.m DESC"])
| print_run_info(runs)
| print("--")
| # Delete the first run
| client.delete_run(run_id=run.info.run_id)
| # Search only deleted runs under the experiment id and use a case insensitive pattern
| # in the filter_string for the tag.
| filter_string = "tags.s.release ILIKE '%rc%'"
| runs = client.search_runs(
| experiment_id, run_view_type=ViewType.DELETED_ONLY, filter_string=filter_string
| )
| print_run_info(runs)
|
| .. code-block:: text
| :caption: Output
|
| run_id: 0efb2a68833d4ee7860a964fad31cb3f
| lifecycle_stage: active
| metrics: {'m': 2.5}
| tags: {'s.release': '1.2.0-GA'}
| run_id: 7ab027fd72ee4527a5ec5eafebb923b8
| lifecycle_stage: active
| metrics: {'m': 1.55}
| tags: {'s.release': '1.1.0-RC'}
| --
| run_id: 7ab027fd72ee4527a5ec5eafebb923b8
| lifecycle_stage: deleted
| metrics: {'m': 1.55}
| tags: {'s.release': '1.1.0-RC'}
|
| search_traces(self, experiment_ids: list[str] | None = None, filter_string: str | None = None, max_results: int = 100, order_by: list[str] | None = None, page_token: str | None = None, run_id: str | None = None, include_spans: bool = True, model_id: str | None = None, locations: list[str] | None = None, flush: bool = False) -> mlflow.store.entities.paged_list.PagedList[mlflow.entities.trace.Trace]
| .. Note:: Parameter ``experiment_ids`` is deprecated. Use ``locations`` instead.
|
| Return traces that match the given list of search expressions within the experiments.
|
| Args:
| experiment_ids: List of experiment ids to scope the search.
| filter_string: A search filter string.
| max_results: Maximum number of traces desired.
| order_by: List of order_by clauses.
| page_token: Token specifying the next page of results. It should be obtained from
| a ``search_traces`` call.
| run_id: A run id to scope the search. When a trace is created under an active run,
| it will be associated with the run and you can filter on the run id to retrieve
| the trace.
| include_spans: If ``True``, include spans in the returned traces. Otherwise, only
| the trace metadata is returned, e.g., trace ID, start time, end time, etc,
| without any spans.
| model_id: If specified, return traces associated with the model ID.
| locations: A list of locations to search over. To search over experiments, provide
| a list of experiment IDs. To search over UC tables on databricks, provide
| a list of locations in the format `<catalog_name>.<schema_name>`.
| flush: If ``True``, flush any pending async trace writes before searching.
| Useful in tests or scripts to ensure all traces are visible. Default to ``False``.
|
| Returns:
| A :py:class:`PagedList <mlflow.store.entities.PagedList>` of
| :py:class:`Trace <mlflow.entities.Trace>` objects that satisfy the search
| expressions. If the underlying tracking store supports pagination, the token for the
| next page may be obtained via the ``token`` attribute of the returned object; however,
| some store implementations may not support pagination and thus the returned token would
| not be meaningful in such cases.
|
| set_dataset_tags(self, dataset_id: str, tags: dict[str, typing.Any]) -> None
| Set tags for a dataset.
|
| This implements an upsert operation - existing tags are merged with new tags.
| To remove a tag, set its value to None.
|
| Args:
| dataset_id: The ID of the dataset to update.
| tags: Dictionary of tags to update. Setting a value to None removes the tag.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Set tags for a dataset
| client.set_dataset_tags(
| dataset_id="dataset123",
| tags={
| "environment": "production",
| "version": "2.0",
| "deprecated": None, # This removes the 'deprecated' tag
| },
| )
|
| set_experiment_tag(self, experiment_id: str, key: str, value: Any) -> None
| Set a tag on the experiment with the specified ID. Value is converted to a string.
|
| Args:
| experiment_id: String ID of the experiment.
| key: Name of the tag.
| value: Tag value (converted to a string).
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| # Create an experiment and set its tag
| client = MlflowClient()
| experiment_id = client.create_experiment("Social Media NLP Experiments")
| client.set_experiment_tag(experiment_id, "nlp.framework", "Spark NLP")
|
| # Fetch experiment metadata information
| experiment = client.get_experiment(experiment_id)
| print(f"Name: {experiment.name}")
| print(f"Tags: {experiment.tags}")
|
| .. code-block:: text
|
| Name: Social Media NLP Experiments
| Tags: {'nlp.framework': 'Spark NLP'}
|
| set_logged_model_tags(self, model_id: str, tags: dict[str, typing.Any]) -> None
| Set tags on the specified logged model.
|
| Args:
| model_id: ID of the model.
| tags: Tags to set on the model.
|
| Returns:
| None
|
| set_mcp_server_alias(self, name: str, alias: str, version: str) -> None
|
| set_mcp_server_tag(self, name: str, key: str, value: str) -> None
|
| set_mcp_server_version_tag(self, name: str, version: str, key: str, value: str) -> None
|
| set_model_version_tag(self, name: str, version: str | None = None, key: str | None = None, value: Any = None, stage: str | None = None) -> None
| Set a tag for the model version.
| When stage is set, tag will be set for latest model version of the stage.
| Setting both version and stage parameter will result in error.
|
| Args:
| name: Registered model name.
| version: Registered model version.
| key: Tag key to log. key is required.
| value: Tag value to log. value is required.
| stage: Registered model stage.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_version_info(mv):
| print(f"Name: {mv.name}")
| print(f"Version: {mv.version}")
| print(f"Tags: {mv.tags}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a new version of the rfr model under the registered model name
| # and set a tag
| model_uri = f"runs:/{run.info.run_id}/sklearn-model"
| mv = client.create_model_version(name, model_uri, run.info.run_id)
| print_model_version_info(mv)
| print("--")
|
| # Tag using model version
| client.set_model_version_tag(name, mv.version, "t", "1")
|
| # Tag using model stage
| client.set_model_version_tag(name, key="t1", value="1", stage=mv.current_stage)
| mv = client.get_model_version(name, mv.version)
| print_model_version_info(mv)
|
| .. code-block:: text
| :caption: Output
|
| Name: RandomForestRegression
| Version: 1
| Tags: {}
| --
| Name: RandomForestRegression
| Version: 1
| Tags: {'t': '1', 't1': '1'}
|
| set_prompt_alias(self, name: str, alias: str, version: int) -> None
| Set an alias for a :py:class:`Prompt <mlflow.entities.Prompt>`.
|
| Args:
| name: The name of the prompt.
| alias: The alias to set for the prompt.
| version: The version of the prompt.
|
| set_prompt_tag(self, name: str, key: str, value: str) -> None
| Set a tag on a prompt.
|
| This method delegates directly to the store, providing full Unity Catalog support
| when used with Unity Catalog registries.
|
| Args:
| name: Name of the prompt.
| key: Tag key.
| value: Tag value.
|
| Example:
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
| client.set_prompt_tag("my_prompt", "environment", "production")
|
| set_prompt_version_tag(self, name: str, version: str | int, key: str, value: str) -> None
| Set a tag on a specific prompt version.
|
| Args:
| name: The name of the prompt.
| version: The version number of the prompt.
| key: The tag key.
| value: The tag value.
|
| set_registered_model_alias(self, name: str, alias: str, version: str) -> None
| Set a registered model alias pointing to a model version.
|
| Args:
| name: Registered model name.
| alias: Name of the alias. Note that aliases of the format ``v<number>``, such as
| ``v9`` and ``v42``, are reserved and cannot be set.
| version: Registered model version number.
|
| .. code-block:: Python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_info(rm):
| print("--Model--")
| print("name: {}".format(rm.name))
| print("aliases: {}".format(rm.aliases))
|
|
| def print_model_version_info(mv):
| print("--Model Version--")
| print("Name: {}".format(mv.name))
| print("Version: {}".format(mv.version))
| print("Aliases: {}".format(mv.aliases))
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, artifact_path="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
| model = client.get_registered_model(name)
| print_model_info(model)
|
| # Create a new version of the rfr model under the registered model name
| model_uri = "runs:/{}/sklearn-model".format(run.info.run_id)
| mv = client.create_model_version(name, model_uri, run.info.run_id)
| print_model_version_info(mv)
|
| # Set registered model alias
| client.set_registered_model_alias(name, "test-alias", mv.version)
| print()
| print_model_info(model)
| print_model_version_info(mv)
|
| .. code-block:: text
| :caption: Output
|
| --Model--
| name: RandomForestRegression
| aliases: {}
|
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: []
|
| --Model--
| name: RandomForestRegression
| aliases: {"test-alias": "1"}
|
| --Model Version--
| Name: RandomForestRegression
| Version: 1
| Aliases: ["test-alias"]
|
| set_registered_model_tag(self, name, key, value) -> None
| Set a tag for the registered model.
|
| Args:
| name: Registered model name.
| key: Tag key to log.
| value: Tag value log.
|
| .. code-block:: Python
| :caption: Example
|
| import mlflow
| from mlflow import MlflowClient
|
|
| def print_model_info(rm):
| print("--")
| print("name: {}".format(rm.name))
| print("tags: {}".format(rm.tags))
|
|
| name = "SocialMediaTextAnalyzer"
| tags = {"nlp.framework1": "Spark NLP"}
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| client = MlflowClient()
|
| # Create registered model, set an additional tag, and fetch
| # update model info
| client.create_registered_model(name, tags, desc)
| model = client.get_registered_model(name)
| print_model_info(model)
| client.set_registered_model_tag(name, "nlp.framework2", "VADER")
| model = client.get_registered_model(name)
| print_model_info(model)
|
| .. code-block:: text
| :caption: Output
|
| --
| name: SocialMediaTextAnalyzer
| tags: {'nlp.framework1': 'Spark NLP'}
| --
| name: SocialMediaTextAnalyzer
| tags: {'nlp.framework1': 'Spark NLP', 'nlp.framework2': 'VADER'}
|
| set_tag(self, run_id: str, key: str, value: Any, synchronous: bool | None = None) -> mlflow.utils.async_logging.run_operations.RunOperations | None
| Set a tag on the run with the specified ID. Value is converted to a string.
|
| Args:
| run_id: String ID of the run.
| key: Tag name. This string may only contain alphanumerics, underscores (_), dashes (-),
| periods (.), spaces ( ), and slashes (/). All backend stores will support keys up to
| length 250, but some may support larger keys.
| value: Tag value, but will be string-ified if not. All backend stores will support
| values up to length 5000, but some may support larger values.
| synchronous: *Experimental* If True, blocks until the metric is logged successfully.
| If False, logs the metric asynchronously and returns a future representing the
| logging operation. If None, read from environment variable
| `MLFLOW_ENABLE_ASYNC_LOGGING`, which defaults to False if not set.
|
| Returns:
| When `synchronous=True` or None, returns None. When `synchronous=False`, returns an
| `mlflow.utils.async_logging.run_operations.RunOperations` instance that represents
| future for logging operation.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_run_info(run):
| print(f"run_id: {run.info.run_id}")
| print(f"Tags: {run.data.tags}")
|
|
| # Create a run under the default experiment (whose id is '0').
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| print_run_info(run)
| print("--")
| # Set a tag and fetch updated run info
| client.set_tag(run.info.run_id, "nlp.framework", "Spark NLP")
| run = client.get_run(run.info.run_id)
| print_run_info(run)
|
| .. code-block:: text
| :caption: Output
|
| run_id: 4f226eb5758145e9b28f78514b59a03b
| Tags: {}
| --
| run_id: 4f226eb5758145e9b28f78514b59a03b
| Tags: {'nlp.framework': 'Spark NLP'}
|
| set_terminated(self, run_id: str, status: str | None = None, end_time: int | None = None) -> None
| Set a run's status to terminated.
|
| Args:
| run_id: The ID of the run to terminate.
| status: A string value of :py:class:`mlflow.entities.RunStatus`. Defaults to "FINISHED".
| end_time: If not provided, defaults to the current time.
|
| .. code-block:: python
|
| from mlflow import MlflowClient
|
|
| def print_run_info(r):
| print(f"run_id: {r.info.run_id}")
| print(f"status: {r.info.status}")
|
|
| # Create a run under the default experiment (whose id is '0').
| # Since this is low-level CRUD operation, this method will create a run.
| # To end the run, you'll have to explicitly terminate it.
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| print_run_info(run)
| print("--")
|
| # Terminate the run and fetch updated status. By default,
| # the status is set to "FINISHED". Other values you can
| # set are "KILLED", "FAILED", "RUNNING", or "SCHEDULED".
| client.set_terminated(run.info.run_id, status="KILLED")
| run = client.get_run(run.info.run_id)
| print_run_info(run)
|
| .. code-block:: text
|
| run_id: 575fb62af83f469e84806aee24945973
| status: RUNNING
| --
| run_id: 575fb62af83f469e84806aee24945973
| status: KILLED
|
| set_trace_tag(self, trace_id: str, key: str, value: str)
| .. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
|
| Set a tag on the trace with the given trace ID.
|
| The trace can be an active one or the one that has already ended and recorded in the
| backend. Below is an example of setting a tag on an active trace. You can replace the
| ``trace_id`` parameter to set a tag on an already ended trace.
|
| .. code-block:: python
| :test:
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| root_span = client.start_trace("my_trace")
| client.set_trace_tag(root_span.trace_id, "key", "value")
| client.end_trace(root_span.trace_id)
|
| Args:
| trace_id: The ID of the trace to set the tag on.
| key: The string key of the tag. Must be at most 250 characters long, otherwise
| it will be truncated when stored.
| value: The string value of the tag. Must be at most 250 characters long, otherwise
| it will be truncated when stored.
|
| start_span(self, name: str, trace_id: str, parent_id: str, span_type: str = 'UNKNOWN', inputs: typing.Any | None = None, attributes: dict[str, typing.Any] | None = None, start_time_ns: int | None = None, links: list[mlflow.entities.link.Link] | None = None) -> mlflow.entities.span.Span
| .. Note:: Parameter ``request_id`` is deprecated. Use ``trace_id`` instead.
|
| Create a new span and start it without attaching it to the global trace context.
|
| This is an imperative API to manually create a new span under a specific trace id
| and parent span, unlike the higher-level APIs like
| :py:func:`@mlflow.trace <mlflow.trace>` decorator and
| :py:func:`with mlflow.start_span() <mlflow.start_span>` context manager, which
| automatically manage the span lifecycle and parent-child relationship.
|
| This API is useful for the case where the automatic context management is not
| sufficient, such as callback-based instrumentation where span start and end are
| not in the same call stack, or multi-threaded applications where the context is
| not propagated automatically.
|
| This API requires a parent span ID to be provided explicitly. If you haven't
| started any span yet, use the :py:func:`start_trace() <start_trace>` method to
| start a new trace and a root span.
|
| .. warning::
|
| The span created with this method needs to be ended explicitly by calling
| the :py:func:`end_span() <end_span>` method. Otherwise the span will be
| recorded with the incorrect end time and status ``TRACE_STATUS_UNSPECIFIED``.
|
| .. tip::
|
| Instead of creating a root span with the :py:func:`start_trace() <start_trace>`
| method, you can also use this method within the context of a parent span created
| by the fluent APIs like :py:func:`@mlflow.trace <mlflow.trace>` and
| :py:func:`with mlflow.start_span() <mlflow.start_span>`, by passing its span
| ids the parent. This flexibility allows you to use the imperative APIs in
| conjunction with the fluent APIs like below:
|
| .. code-block:: python
| :test:
|
| import mlflow
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| with mlflow.start_span("parent_span") as parent_span:
| child_span = client.start_span(
| name="child_span",
| trace_id=parent_span.trace_id,
| parent_id=parent_span.span_id,
| )
|
| # Do something...
|
| client.end_span(
| trace_id=parent_span.trace_id,
| span_id=child_span.span_id,
| )
|
| However, **the opposite does not work**. You cannot use the fluent APIs within
| the span created by this MlflowClient API. This is because the fluent APIs
| fetches the current span from the managed context, which is not set by the MLflow
| Client APIs. Once you create a span with the MLflow Client APIs, all children
| spans must be created with the MLflow Client APIs. Please be cautious when using
| this mixed approach, as it can lead to unexpected behavior if not used properly.
|
| Args:
| name: The name of the span.
| trace_id: The ID of the trace to attach the span to. This is synonym to
| trace_id` in OpenTelemetry.
| parent_id: The ID of the parent span. The parent span can be a span created by
| both fluent APIs like `with mlflow.start_span()`, and imperative APIs like this.
| span_type: The type of the span. Can be either a string or a
| :py:class:`SpanType <mlflow.entities.SpanType>` enum value.
| inputs: Inputs to set on the span.
| attributes: A dictionary of attributes to set on the span.
| start_time_ns: The start time of the span in nano seconds since the UNIX epoch.
| If not provided, the current time will be used.
| links: A list of :py:class:`Link <mlflow.entities.Link>` objects to associate with
| the span.
|
| Returns:
| An :py:class:`mlflow.entities.Span` object representing the span.
|
| Example:
|
| .. code-block:: python
| :test:
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| span = client.start_trace("my_trace")
|
| x = 2
|
| # Create a child span
| child_span = client.start_span(
| "child_span",
| trace_id=span.trace_id,
| parent_id=span.span_id,
| inputs={"x": x},
| )
|
| y = x**2
|
| client.end_span(
| trace_id=child_span.trace_id,
| span_id=child_span.span_id,
| attributes={"factor": 2},
| outputs={"y": y},
| )
|
| client.end_trace(span.trace_id)
|
| start_trace(self, name: str, span_type: str = 'UNKNOWN', inputs: typing.Any | None = None, attributes: dict[str, str] | None = None, tags: dict[str, str] | None = None, experiment_id: str | None = None, start_time_ns: int | None = None, run_id: str | None = None, links: list[mlflow.entities.link.Link] | None = None) -> mlflow.entities.span.Span
| Create a new trace object and start a root span under it.
|
| This is an imperative API to manually create a new span under a specific trace id and
| parent span, unlike the higher-level APIs like :py:func:`@mlflow.trace <mlflow.trace>`
| and :py:func:`with mlflow.start_span() <mlflow.start_span>`, which automatically manage
| the span lifecycle and parent-child relationship. You only need to call this method
| when using the :py:func:`start_span() <start_span>` method of MlflowClient to create
| spans.
|
| .. attention::
|
| A trace started with this method must be ended by calling
| ``MlflowClient().end_trace(trace_id)``. Otherwise the trace will be not recorded.
|
| Args:
| name: The name of the trace (and the root span).
| span_type: The type of the span.
| inputs: Inputs to set on the root span of the trace.
| attributes: A dictionary of attributes to set on the root span of the trace.
| tags: A dictionary of tags to set on the trace.
| experiment_id: The ID of the experiment to create the trace in. If not provided,
| MLflow will look for valid experiment in the following order: activated using
| :py:func:`mlflow.set_experiment() <mlflow.set_experiment>`,
| ``MLFLOW_EXPERIMENT_NAME`` environment variable, ``MLFLOW_EXPERIMENT_ID``
| environment variable, or the default experiment as defined by the tracking server.
| start_time_ns: The start time of the trace in nanoseconds since the UNIX epoch.
| run_id: The ID of the MLflow run to associate with the trace. If provided, the
| trace will be linked to this run.
| links: A list of :py:class:`Link <mlflow.entities.Link>` objects to associate with
| the root span.
|
| Returns:
| An :py:class:`Span <mlflow.entities.Span>` object
| representing the root span of the trace.
|
| Example:
|
| .. code-block:: python
| :test:
|
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| root_span = client.start_trace("my_trace")
| trace_id = root_span.trace_id
|
| # Create a child span
| child_span = client.start_span(
| "child_span", trace_id=trace_id, parent_id=root_span.span_id
| )
| # Do something...
| client.end_span(trace_id=trace_id, span_id=child_span.span_id)
|
| client.end_trace(trace_id)
|
| test_webhook(self, webhook_id: str, event: Union[Literal['registered_model.created', 'model_version.created', 'model_version_tag.set', 'model_version_tag.deleted', 'model_version_alias.created', 'model_version_alias.deleted', 'prompt.created', 'prompt_version.created', 'prompt_tag.set', 'prompt_tag.deleted', 'prompt_version_tag.set', 'prompt_version_tag.deleted', 'prompt_alias.created', 'prompt_alias.deleted', 'budget_policy.exceeded'], mlflow.entities.webhook.WebhookEvent, NoneType] = None) -> mlflow.entities.webhook.WebhookTestResult
| Test a webhook by sending a test payload.
|
| Args:
| webhook_id: Webhook ID to test.
| event: Optional event type to test. Can be a WebhookEvent object or a string in
| "entity.action" format (e.g., "model_version.created"). If not specified, uses
| the first event from webhook.
|
| Returns:
| WebhookTestResult indicating success/failure and response details.
|
| transition_model_version_stage(self, name: str, version: str, stage: str, archive_existing_versions: bool = False) -> mlflow.entities.model_registry.model_version.ModelVersion
| .. Warning:: ``mlflow.tracking.client.MlflowClient.transition_model_version_stage`` is deprecated since 2.9.0. Model registry stages will be removed in a future major release. To learn more about the deprecation of model registry stages, see our migration guide here: https://mlflow.org/docs/latest/model-registry.html#migrating-from-stages
|
| Update model version stage.
|
| Args:
| name: Registered model name.
| version: Registered model version.
| stage: New desired stage for this model version.
| archive_existing_versions: If this flag is set to ``True``, all existing model
| versions in the stage will be automatically moved to the "archived" stage. Only
| valid when ``stage`` is ``"staging"`` or ``"production"`` otherwise an error will be
| raised.
|
| Returns:
| A single :py:class:`mlflow.entities.model_registry.ModelVersion` object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_version_info(mv):
| print(f"Name: {mv.name}")
| print(f"Version: {mv.version}")
| print(f"Description: {mv.description}")
| print(f"Stage: {mv.current_stage}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| desc = "A new version of the model using ensemble trees"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
|
| # Create a new version of the rfr model under the registered model name
| model_uri = f"runs:/{run.info.run_id}/sklearn-model"
| mv = client.create_model_version(name, model_uri, run.info.run_id, description=desc)
| print_model_version_info(mv)
| print("--")
| # transition model version from None -> staging
| mv = client.transition_model_version_stage(name, mv.version, "staging")
| print_model_version_info(mv)
|
| .. code-block:: text
| :caption: Output
|
| Name: RandomForestRegression
| Version: 1
| Description: A new version of the model using ensemble trees
| Stage: None
| --
| Name: RandomForestRegression
| Version: 1
| Description: A new version of the model using ensemble trees
| Stage: Staging
|
| unlink_traces_from_run(self, trace_ids: list[str], run_id: str) -> None
| Unlink multiple traces from a run by removing entity associations.
|
| Args:
| trace_ids: List of trace IDs to unlink from the run.
| run_id: ID of the run to unlink traces from.
|
| Example:
| .. code-block:: python
|
| import mlflow
| from mlflow import MlflowClient
|
| client = MlflowClient()
|
| # Unlink multiple V4 traces from a run
| client.unlink_traces_from_run(
| trace_ids=[
| "trace://catalog.schema/abc123",
| "trace://catalog.schema/def456",
| ],
| run_id="run_abc",
| )
|
| update_mcp_access_endpoint(self, server_name: str, endpoint_id: str, url: str | None = <object object at 0x0000025F348EA210>, transport_type: mlflow.entities.mcp_server.MCPRemoteTransportType | None = <object object at 0x0000025F348EA210>, server_version: str | None = <object object at 0x0000025F348EA210>, server_alias: str | None = <object object at 0x0000025F348EA210>) -> mlflow.entities.mcp_access_endpoint.MCPAccessEndpoint
|
| update_mcp_server(self, name: str, display_name: str | None = <object object at 0x0000025F348EA210>, description: str | None = <object object at 0x0000025F348EA210>, icons: list[mlflow.store.tracking.mcp_server_registry.abstract_mixin.MCPIcon] | None = <object object at 0x0000025F348EA210>) -> mlflow.entities.mcp_server.MCPServer
|
| update_mcp_server_version(self, name: str, version: str, status: mlflow.entities.mcp_server.MCPStatus | None = <object object at 0x0000025F348EA210>, tools: list[mlflow.entities.mcp_server.MCPTool] | None = <object object at 0x0000025F348EA210>, connect_options: dict[str, mlflow.entities.mcp_server_version.ConnectOptionSettings] | None = <object object at 0x0000025F348EA210>) -> mlflow.entities.mcp_server_version.MCPServerVersion
|
| update_model_version(self, name: str, version: str, description: str | None = None) -> mlflow.entities.model_registry.model_version.ModelVersion
| Update metadata associated with a model version in backend.
|
| Args:
| name: Name of the containing registered model.
| version: Version number of the model version.
| description: New description.
|
| Returns:
| A single :py:class:`mlflow.entities.model_registry.ModelVersion` object.
|
| .. code-block:: python
| :caption: Example
|
| import mlflow.sklearn
| from mlflow import MlflowClient
| from mlflow.models import infer_signature
| from sklearn.datasets import make_regression
| from sklearn.ensemble import RandomForestRegressor
|
|
| def print_model_version_info(mv):
| print(f"Name: {mv.name}")
| print(f"Version: {mv.version}")
| print(f"Description: {mv.description}")
|
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| params = {"n_estimators": 3, "random_state": 42}
| name = "RandomForestRegression"
| X, y = make_regression(n_features=4, n_informative=2, random_state=0, shuffle=False)
| rfr = RandomForestRegressor(**params).fit(X, y)
| signature = infer_signature(X, rfr.predict(X))
|
| # Log MLflow entities
| with mlflow.start_run() as run:
| mlflow.log_params(params)
| mlflow.sklearn.log_model(rfr, name="sklearn-model", signature=signature)
|
| # Register model name in the model registry
| client = MlflowClient()
| client.create_registered_model(name)
| # Create a new version of the rfr model under the registered model name
| model_uri = f"runs:/{run.info.run_id}/sklearn-model"
| mv = client.create_model_version(name, model_uri, run.info.run_id)
| print_model_version_info(mv)
| print("--")
| # Update model version's description
| desc = "A new version of the model using ensemble trees"
| mv = client.update_model_version(name, mv.version, desc)
| print_model_version_info(mv)
|
| .. code-block:: text
| :caption: Output
|
| Name: RandomForestRegression
| Version: 1
| Description: None
| --
| Name: RandomForestRegression
| Version: 1
| Description: A new version of the model using ensemble trees
|
| update_registered_model(self, name: str, description: str | None = None, deployment_job_id: str | None = None) -> mlflow.entities.model_registry.registered_model.RegisteredModel
| Updates metadata for RegisteredModel entity. Input field ``description`` should be non-None.
| Backend raises exception if a registered model with given name does not exist.
|
| Args:
| name: Name of the registered model to update.
| description: (Optional) New description.
| deployment_job_id: Optional deployment job ID.
|
| Returns:
| A single updated :py:class:`mlflow.entities.model_registry.RegisteredModel` object.
|
| .. code-block:: python
| :caption: Example
|
| def print_registered_model_info(rm):
| print(f"name: {rm.name}")
| print(f"tags: {rm.tags}")
| print(f"description: {rm.description}")
|
|
| name = "SocialMediaTextAnalyzer"
| tags = {"nlp.framework": "Spark NLP"}
| desc = "This sentiment analysis model classifies the tone-happy, sad, angry."
|
| mlflow.set_tracking_uri("sqlite:///mlruns.db")
| client = MlflowClient()
| client.create_registered_model(name, tags, desc)
| print_registered_model_info(client.get_registered_model(name))
| print("--")
|
| # Update the model's description
| desc = "This sentiment analysis model classifies tweets' tone: happy, sad, angry."
| client.update_registered_model(name, desc)
| print_registered_model_info(client.get_registered_model(name))
|
| .. code-block:: text
| :caption: Output
|
| name: SocialMediaTextAnalyzer
| tags: {'nlp.framework': 'Spark NLP'}
| description: This sentiment analysis model classifies the tone-happy, sad, angry.
| --
| name: SocialMediaTextAnalyzer
| tags: {'nlp.framework': 'Spark NLP'}
| description: This sentiment analysis model classifies tweets' tone: happy, sad, angry.
|
| update_run(self, run_id: str, status: str | None = None, name: str | None = None) -> None
| Update a run with the specified ID to a new status or name.
|
| Args:
| run_id: The ID of the Run to update.
| status: The new status of the run to set, if specified. At least one of ``status`` or
| ``name`` should be specified.
| name: The new name of the run to set, if specified. At least one of ``name`` or
| ``status`` should be specified.
|
| .. code-block:: python
| :caption: Example
|
| from mlflow import MlflowClient
|
|
| def print_run_info(run):
| print(f"run_id: {run.info.run_id}")
| print(f"run_name: {run.info.run_name}")
| print(f"status: {run.info.status}")
|
|
| # Create a run under the default experiment (whose id is '0').
| client = MlflowClient()
| experiment_id = "0"
| run = client.create_run(experiment_id)
| print_run_info(run)
| print("--")
|
| # Update run and fetch info
| client.update_run(run.info.run_id, "FINISHED", "new_name")
| run = client.get_run(run.info.run_id)
| print_run_info(run)
|
| .. code-block:: text
| :caption: Output
|
| run_id: 1cf6bf8bf6484dd8a598bd43be367b20
| run_name: judicious-hog-915
| status: RUNNING
| --
| run_id: 1cf6bf8bf6484dd8a598bd43be367b20
| run_name: new_name
| status: FINISHED
|
| update_webhook(self, webhook_id: str, name: str | None = None, description: str | None = None, url: str | None = None, events: list[typing.Union[typing.Literal['registered_model.created', 'model_version.created', 'model_version_tag.set', 'model_version_tag.deleted', 'model_version_alias.created', 'model_version_alias.deleted', 'prompt.created', 'prompt_version.created', 'prompt_tag.set', 'prompt_tag.deleted', 'prompt_version_tag.set', 'prompt_version_tag.deleted', 'prompt_alias.created', 'prompt_alias.deleted', 'budget_policy.exceeded'], mlflow.entities.webhook.WebhookEvent]] | None = None, secret: str | None = None, status: str | mlflow.entities.webhook.WebhookStatus | None = None) -> mlflow.entities.webhook.Webhook
| Update an existing webhook.
|
| Args:
| webhook_id: Webhook ID.
| name: New webhook name.
| description: New webhook description.
| url: New webhook URL.
| events: New list of events. Can be strings or `WebhookEvent` objects.
| secret: New webhook secret.
| status: New webhook status. Can be string or WebhookStatus enum.
| Valid statuses: "ACTIVE", "DISABLED"
|
| Returns:
| A :py:class:`mlflow.entities.webhook.Webhook` object representing the updated webhook.
|
| update_workspace(self, name: str, description: str | None = None, default_artifact_root: str | None = None, trace_archival_config: mlflow.entities.workspace.TraceArchivalConfig | None = None) -> mlflow.entities.workspace.Workspace
| Update metadata for an existing workspace.
|
| Args:
| name: The name of the workspace to update.
| description: New description, or ``None`` to leave unchanged.
| default_artifact_root: New artifact root URI, empty string to clear, or ``None``.
| trace_archival_config: Optional Python-side grouping for trace archival settings.
| Use ``TraceArchivalConfig.location`` to update the archival storage URI/root and
| ``TraceArchivalConfig.retention`` to update the archived-trace retention duration
| such as ``30d`` or ``12h``. Use an empty string to clear an existing value, or
| leave fields as ``None`` to keep the current value unchanged.
|
| Returns:
| The updated workspace.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| tracking_uri
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FUNCTIONS
_get_artifact_repo(run_id)
_get_store(store_uri=None, artifact_uri=None)
get_registry_uri() -> str
Get the current registry URI. If none has been specified, defaults to the tracking URI.
Returns:
The registry URI.
.. code-block:: python
# Get the current model registry uri
mr_uri = mlflow.get_registry_uri()
print(f"Current model registry uri: {mr_uri}")
# Get the current tracking uri
tracking_uri = mlflow.get_tracking_uri()
print(f"Current tracking uri: {tracking_uri}")
# They should be the same
assert mr_uri == tracking_uri
.. code-block:: text
Current model registry uri: file:///.../mlruns
Current tracking uri: file:///.../mlruns
get_tracking_uri() -> str
Get the current tracking URI. This may not correspond to the tracking URI of
the currently active run, since the tracking URI can be updated via ``set_tracking_uri``.
Returns:
The tracking URI.
.. code-block:: python
import mlflow
# Get the current tracking uri
tracking_uri = mlflow.get_tracking_uri()
print(f"Current tracking uri: {tracking_uri}")
.. code-block:: text
Current tracking uri: sqlite:///mlflow.db
is_tracking_uri_set()
Returns True if the tracking URI has been set, False otherwise.
set_registry_uri(uri: str) -> None
Set the registry server URI. This method is especially useful if you have a registry server
that's different from the tracking server.
Args:
uri: An empty string, or a local file path, prefixed with ``file:/``. Data is stored
locally at the provided file (or ``./mlruns`` if empty). An HTTP URI like
``https://my-tracking-server:5000`` or ``http://my-oss-uc-server:8080``. A Databricks
workspace, provided as the string "databricks" or, to use a Databricks CLI
`profile <https://github.com/databricks/databricks-cli#installation>`_,
"databricks://<profileName>".
.. code-block:: python
:caption: Example
import mflow
# Set model registry uri, fetch the set uri, and compare
# it with the tracking uri. They should be different
mlflow.set_registry_uri("sqlite:////tmp/registry.db")
mr_uri = mlflow.get_registry_uri()
print(f"Current registry uri: {mr_uri}")
tracking_uri = mlflow.get_tracking_uri()
print(f"Current tracking uri: {tracking_uri}")
# They should be different
assert tracking_uri != mr_uri
.. code-block:: text
:caption: Output
Current registry uri: sqlite:////tmp/registry.db
Current tracking uri: file:///.../mlruns
set_tracking_uri(uri: str | pathlib.Path) -> None
Set the tracking server URI. This does not affect the
currently active run (if one exists), but takes effect for successive runs.
Args:
uri:
- An empty string, or a local file path, prefixed with ``file:/``. Data is stored
locally at the provided file (or ``./mlruns`` if empty).
- An HTTP URI like ``https://my-tracking-server:5000``.
- A Databricks workspace, provided as the string "databricks" or, to use a Databricks
CLI `profile <https://github.com/databricks/databricks-cli#installation>`_,
"databricks://<profileName>".
- A :py:class:`pathlib.Path` instance
.. code-block:: python
:test:
:caption: Example
import mlflow
mlflow.set_tracking_uri("file:///tmp/my_tracking")
tracking_uri = mlflow.get_tracking_uri()
print(f"Current tracking uri: {tracking_uri}")
.. code-block:: text
:caption: Output
Current tracking uri: file:///tmp/my_tracking
DATA
__all__ = ['get_tracking_uri', 'set_tracking_uri', 'is_tracking_uri_se...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\tracking\__init__.py
mlflow.transformers
Python Library Documentation: package mlflow.transformers in mlflow
NAME
mlflow.transformers - MLflow module for HuggingFace/transformer support.
PACKAGE CONTENTS
flavor_config
llm_inference_utils
model_io
peft
signature
torch_utils
FUNCTIONS
autolog(log_input_examples=False, log_model_signatures=False, log_models=False, log_datasets=False, disable=False, exclusive=False, disable_for_unsupported_versions=False, silent=False, extra_tags=None)
.. Note:: Autologging is known to be compatible with the following package versions: ``4.43.4`` <= ``transformers`` <= ``5.14.1``. Autologging may not succeed when used with package versions outside of this range.
This autologging integration is solely used for disabling spurious autologging of irrelevant
sub-models that are created during the training and evaluation of transformers-based models.
Autologging functionality is not implemented fully for the transformers flavor.
generate_signature_output(pipeline, data, model_config=None, params=None, flavor_config=None)
.. Warning:: ``mlflow.transformers.generate_signature_output`` is deprecated since 3.11.0. Signatures are now automatically inferred when `input_example` is provided to `mlflow.transformers.log_model()` or `mlflow.transformers.save_model()`. This method will be removed in a future release.
Utility for generating the response output for the purposes of extracting an output signature
for model saving and logging. This function simulates loading of a saved model or pipeline
as a ``pyfunc`` model without having to incur a write to disk.
.. deprecated:: 3.11.0
Use the ``input_example`` parameter in
:func:`mlflow.transformers.log_model()` or :func:`mlflow.transformers.save_model()`
instead. Signatures are now automatically inferred when ``input_example`` is provided.
Args:
pipeline: A ``transformers`` pipeline object. Note that component-level or model-level
inputs are not permitted for extracting an output example.
data: An example input that is compatible with the given pipeline
model_config: Any additional model configuration, provided as kwargs, to inform
the format of the output type from a pipeline inference call.
params: A dictionary of additional parameters to pass to the pipeline for inference.
flavor_config: The flavor configuration for the model.
Returns:
The output from the ``pyfunc`` pipeline wrapper's ``predict`` method
get_default_conda_env(model)
Returns:
The default Conda environment for MLflow Models produced with the ``transformers``
flavor, based on the model instance framework type of the model to be logged.
get_default_pip_requirements(model) -> 'list[str]'
Args:
model: The model instance to be saved in order to provide the required underlying
deep learning execution framework dependency requirements. Note that this must
be the actual model instance and not a Pipeline.
Returns:
A list of default pip requirements for MLflow Models that have been produced with the
``transformers`` flavor. Calls to :py:func:`save_model()` and :py:func:`log_model()`
produce a pip environment that contain these requirements at a minimum.
is_gpu_available()
# This function attempts to determine if a GPU is available for the PyTorch and TensorFlow libraries
load_model(model_uri: 'str', dst_path: 'str | None' = None, return_type='pipeline', device=None, base_model_path: 'str | None' = None, **kwargs)
.. Note:: The 'transformers' MLflow Models integration is known to be compatible with ``4.43.4`` <= ``transformers`` <= ``5.14.1``. MLflow Models integrations with transformers may not succeed when used with package versions outside of this range.
Load a ``transformers`` object from a local file or a run.
Args:
model_uri: The location, in URI format, of the MLflow model. For example:
- ``/Users/me/path/to/local/model``
- ``relative/path/to/local/model``
- ``s3://my_bucket/path/to/model``
- ``runs:/<mlflow_run_id>/run-relative/path/to/model``
- ``mlflow-artifacts:/path/to/model``
For more information about supported URI schemes, see
`Referencing Artifacts <https://www.mlflow.org/docs/latest/tracking.html#
artifact-locations>`_.
dst_path: The local filesystem path to utilize for downloading the model artifact.
This directory must already exist if provided. If unspecified, a local output
path will be created.
return_type: A return type modifier for the stored ``transformers`` object.
If set as "components", the return type will be a dictionary of the saved
individual components of either the ``Pipeline`` or the pre-trained model.
The components for NLP-focused models will typically consist of a
return representation as shown below with a text-classification example:
.. code-block:: python
{"model": BertForSequenceClassification, "tokenizer": BertTokenizerFast}
Vision models will return an ``ImageProcessor`` instance of the appropriate
type, while multi-modal models will return both a ``FeatureExtractor`` and
a ``Tokenizer`` along with the model.
Returning "components" can be useful for certain model types that do not
have the desired pipeline return types for certain use cases.
If set as "pipeline", the model, along with any and all required
``Tokenizer``, ``FeatureExtractor``, ``Processor``, or ``ImageProcessor``
objects will be returned within a ``Pipeline`` object of the appropriate
type defined by the ``task`` set by the model instance type. To override
this behavior, supply a valid ``task`` argument during model logging or
saving. Default is "pipeline".
device: The device on which to load the model. Default is None. Use 0 to
load to the default GPU.
base_model_path: Optional path to a local directory containing the base model
weights. When provided, overrides the base model path stored in the MLflow
artifact at save time. This is useful when the base model is located at a
different path at load time than it was at save time (e.g. different mount
points across environments).
kwargs: Optional configuration options for loading of a ``transformers`` object.
For information on parameters and their usage, see
`transformers documentation <https://huggingface.co/docs/transformers/index>`_.
Returns:
A ``transformers`` model instance or a dictionary of components
log_model(transformers_model, artifact_path: 'str | None' = None, processor=None, task: 'str | None' = None, torch_dtype: 'torch.dtype | None' = None, model_card=None, code_paths: 'list[str] | None' = None, registered_model_name: 'str | None' = None, signature: 'ModelSignature | None' = None, input_example: 'ModelInputExample | None' = None, await_registration_for=300, pip_requirements: 'list[str] | str | None' = None, extra_pip_requirements: 'list[str] | str | None' = None, conda_env=None, metadata: 'dict[str, Any] | None' = None, model_config: 'dict[str, Any] | None' = None, prompt_template: 'str | None' = None, save_pretrained: 'bool' = True, prompts: 'list[str | Prompt] | None' = None, name: 'str | None' = None, params: 'dict[str, Any] | None' = None, tags: 'dict[str, Any] | None' = None, model_type: 'str | None' = None, step: 'int' = 0, model_id: 'str | None' = None, base_model_path: 'str | None' = None, **kwargs)
.. Note:: The 'transformers' MLflow Models integration is known to be compatible with ``4.43.4`` <= ``transformers`` <= ``5.14.1``. MLflow Models integrations with transformers may not succeed when used with package versions outside of this range.
Log a ``transformers`` object as an MLflow artifact for the current run. Note that
logging transformers models with custom code (i.e. models that require
``trust_remote_code=True``) requires ``transformers >= 4.26.0``.
Args:
transformers_model:
The transformers model to save. This can be one of the following format:
1. A transformers `Pipeline` instance.
2. A dictionary that maps required components of a pipeline to the named keys
of ["model", "image_processor", "tokenizer", "feature_extractor"].
The `model` key in the dictionary must map to a value that inherits from
`PreTrainedModel`, `TFPreTrainedModel`, or `FlaxPreTrainedModel`.
All other component entries in the dictionary must support the defined task
type that is associated with the base model type configuration.
3. A string that represents a path to a local/DBFS directory containing a model
checkpoint. The directory must contain a `config.json` file that is required
for loading the transformers model. This is particularly useful when logging
a model that cannot be loaded into memory for serialization.
An example of specifying a `Pipeline` from a default pipeline instantiation:
.. code-block:: python
from transformers import pipeline
fill_pipe = pipeline("fill-mask", "distilroberta-base")
with mlflow.start_run():
mlflow.transformers.log_model(
transformers_model=fill_pipe,
name="model",
)
An example of specifying component-level parts of a transformers model is shown below:
.. code-block:: python
from transformers import AutoModelForMaskedLM, AutoTokenizer
architecture = "distilroberta-base"
tokenizer = AutoTokenizer.from_pretrained(architecture)
model = AutoModelForMaskedLM.from_pretrained(architecture)
with mlflow.start_run():
components = {
"model": model,
"tokenizer": tokenizer,
}
mlflow.transformers.log_model(
transformers_model=components,
name="model",
)
An example of specifying a local checkpoint path is shown below:
.. code-block:: python
with mlflow.start_run():
mlflow.transformers.log_model(
transformers_model="path/to/local/checkpoint",
name="model",
)
artifact_path: Deprecated. Use `name` instead.
processor: An optional ``Processor`` subclass object. Some model architectures,
particularly multi-modal types, utilize Processors to combine text
encoding and image or audio encoding in a single entrypoint.
.. Note:: If a processor is supplied when logging a model, the
model will be unavailable for loading as a ``Pipeline`` or for usage
with pyfunc inference.
task: The transformers-specific task type of the model. These strings are utilized so
that a pipeline can be created with the appropriate internal call architecture
to meet the needs of a given model. If this argument is not specified, the
pipeline utilities within the transformers library will be used to infer the
correct task type. If the value specified is not a supported type within the
version of transformers that is currently installed, an Exception will be thrown.
torch_dtype: The Pytorch dtype applied to the model when loading back. This is useful
when you want to save the model with a specific dtype that is different from the
dtype of the model when it was trained. If not specified, the current dtype of the
model instance will be used.
model_card: An Optional `ModelCard` instance from `huggingface-hub`. If provided, the
contents of the model card will be saved along with the provided
`transformers_model`. If not provided, an attempt will be made to fetch
the card from the base pretrained model that is provided (or the one that is
included within a provided `Pipeline`).
.. Note:: In order for a ModelCard to be fetched (if not provided),
the huggingface_hub package must be installed and the version
must be >=0.10.0
code_paths: A list of local filesystem paths to Python file dependencies (or directories
containing file dependencies). These files are *prepended* to the system path when the model
is loaded. Files declared as dependencies for a given model should have relative
imports declared from a common root path if multiple files are defined with import dependencies
between them to avoid import errors when loading the model.
For a detailed explanation of ``code_paths`` functionality, recommended usage patterns and
limitations, see the
`code_paths usage guide <https://mlflow.org/docs/latest/model/dependencies.html?highlight=code_paths#saving-extra-code-with-an-mlflow-model>`_.
registered_model_name: If given, create a model
version under ``registered_model_name``, also creating a
registered model if one with the given name does not exist.
signature: A Model Signature object that describes the input and output Schema of the
model. The model signature can be inferred using `infer_signature` function
of `mlflow.models.signature`.
.. code-block:: python
:caption: Example
from transformers import pipeline
en_to_de = pipeline("translation_en_to_de")
data = "MLflow is great!"
with mlflow.start_run() as run:
mlflow.transformers.log_model(
transformers_model=en_to_de,
name="english_to_german_translator",
input_example=data,
)
model_uri = f"runs:/{run.info.run_id}/english_to_german_translator"
loaded = mlflow.pyfunc.load_model(model_uri)
print(loaded.predict(data))
# MLflow ist großartig!
If an input_example is provided and the signature is not, a signature will
be inferred automatically and applied to the MLmodel file iff the
pipeline type is a text-based model (NLP). If the pipeline type is not
a supported type, this inference functionality will not function correctly
and a warning will be issued. In order to ensure that a precise signature
is logged, it is recommended to explicitly provide one.
input_example: one or several instances of valid model input. The input example is used
as a hint of what data to feed the model. It will be converted to a Pandas
DataFrame and then serialized to json using the Pandas split-oriented
format, or a numpy array where the example will be serialized to json
by converting it to a list. Bytes are base64-encoded. When the ``signature`` parameter is
``None``, the input example is used to infer a model signature.
await_registration_for: Number of seconds to wait for the model version
to finish being created and is in ``READY`` status.
By default, the function waits for five minutes.
Specify 0 or None to skip waiting.
pip_requirements: Either an iterable of pip requirement strings
(e.g. ``["transformers", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes the environment this model should be run in. If ``None``, a default list of requirements
is inferred by :func:`mlflow.models.infer_pip_requirements` from the current software environment.
If the requirement inference fails, it falls back to using `get_default_pip_requirements`.
Both requirements and constraints are automatically parsed and written to ``requirements.txt`` and
``constraints.txt`` files, respectively, and stored as part of the model. Requirements are also
written to the ``pip`` section of the model's conda environment (``conda.yaml``) file.
extra_pip_requirements: Either an iterable of pip
requirement strings
(e.g. ``["pandas", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes additional pip requirements that are appended to a default set of pip requirements
generated automatically based on the user's current software environment. Both requirements and
constraints are automatically parsed and written to ``requirements.txt`` and ``constraints.txt``
files, respectively, and stored as part of the model. Requirements are also written to the ``pip``
section of the model's conda environment (``conda.yaml``) file.
.. warning::
The following arguments can't be specified at the same time:
- ``conda_env``
- ``pip_requirements``
- ``extra_pip_requirements``
`This example <https://github.com/mlflow/mlflow/blob/master/examples/pip_requirements/pip_requirements.py>`_ demonstrates how to specify pip requirements using
``pip_requirements`` and ``extra_pip_requirements``.
conda_env: Either a dictionary representation of a Conda environment or the path to a conda
environment yaml file. If provided, this describes the environment this model should be run in.
At a minimum, it should specify the dependencies contained in `get_default_conda_env()`.
If ``None``, a conda environment with pip requirements inferred by
:func:`mlflow.models.infer_pip_requirements` is added
to the model. If the requirement inference fails, it falls back to using
`get_default_pip_requirements`. pip requirements from ``conda_env`` are written to a pip
``requirements.txt`` file and the full conda environment is written to ``conda.yaml``.
The following is an *example* dictionary representation of a conda environment::
{
"name": "mlflow-env",
"channels": ["conda-forge"],
"dependencies": [
"python=3.8.15",
{
"pip": [
"transformers==x.y.z"
],
},
],
}
metadata: Custom metadata dictionary passed to the model and stored in the MLmodel file.
model_config:
A dict of valid overrides that can be applied to a pipeline instance during inference.
These arguments are used exclusively for the case of loading the model as a ``pyfunc``
Model or for use in Spark. These values are not applied to a returned Pipeline from a
call to ``mlflow.transformers.load_model()``
.. Warning:: If the key provided is not compatible with either the
Pipeline instance for the task provided or is not a valid
override to any arguments available in the Model, an
Exception will be raised at runtime. It is very important
to validate the entries in this dictionary to ensure
that they are valid prior to saving or logging.
An example of providing overrides for a question generation model:
.. code-block:: python
from transformers import pipeline, AutoTokenizer
task = "text-generation"
architecture = "gpt2"
sentence_pipeline = pipeline(
task=task,
tokenizer=AutoTokenizer.from_pretrained(architecture),
model=architecture,
)
# Validate that the overrides function
prompts = ["Generative models are", "I'd like a coconut so that I can"]
# validation of config prior to save or log
model_config = {
"top_k": 2,
"num_beams": 5,
"max_length": 30,
"temperature": 0.62,
"top_p": 0.85,
"repetition_penalty": 1.15,
}
# Verify that no exceptions are thrown
sentence_pipeline(prompts, **model_config)
with mlflow.start_run():
mlflow.transformers.log_model(
transformers_model=sentence_pipeline,
name="my_sentence_generator",
task=task,
model_config=model_config,
)
prompt_template: A string that, if provided, will be used to format the user's input prior
to inference. The string should contain a single placeholder, ``{prompt}``, which will be
replaced with the user's input. For example: ``"Answer the following question. Q: {prompt} A:"``.
Currently, only the following pipeline types are supported:
- `feature-extraction <https://huggingface.co/transformers/main_classes/pipelines.html#transformers.FeatureExtractionPipeline>`_
- `fill-mask <https://huggingface.co/transformers/main_classes/pipelines.html#transformers.FillMaskPipeline>`_
- `summarization <https://huggingface.co/transformers/main_classes/pipelines.html#transformers.SummarizationPipeline>`_
- `text2text-generation <https://huggingface.co/transformers/main_classes/pipelines.html#transformers.Text2TextGenerationPipeline>`_
- `text-generation <https://huggingface.co/transformers/main_classes/pipelines.html#transformers.TextGenerationPipeline>`_
The following example shows how to log a text-generation pipeline with a prompt template and
use it via the ``python_function`` (pyfunc) flavor:
.. code-block:: python
import mlflow
from transformers import pipeline
# Initialize a text-generation pipeline
generator = pipeline("text-generation", model="gpt2")
# Define a prompt template. The ``{prompt}`` placeholder will be replaced
# with the raw user input at inference time.
prompt_template = "Answer the following question concisely.\n\nQ: {prompt}\nA:"
example_prompt = "What is MLflow?"
# Log the model with the prompt template and an input example
with mlflow.start_run():
model_info = mlflow.transformers.log_model(
transformers_model=generator,
name="qa_text_generator",
prompt_template=prompt_template,
input_example=example_prompt,
)
# Load the model back as a pyfunc model
loaded_model = mlflow.pyfunc.load_model(model_info.model_uri)
# The input to ``predict`` is the raw question string; the prompt template
# is applied internally before calling the underlying transformers pipeline.
loaded_model.predict("What is experiment tracking?")
save_pretrained: If set to ``False``, MLflow will not save the Transformer model weight files,
instead only saving the reference to the HuggingFace Hub model repository and its commit hash.
This is useful when you load the pretrained model from HuggingFace Hub and want to log or save
it to MLflow without modifying the model weights. In such case, specifying this flag to
``False`` will save the storage space and reduce time to save the model. Please refer to the
`Storage-Efficient Model Logging
<../../llms/transformers/large-models.html#transformers-save-pretrained-guide>`_ for more detailed
usage.
.. warning::
If the model is saved with ``save_pretrained`` set to ``False``, the model cannot be
registered to the MLflow Model Registry. In order to convert the model to the one that
can be registered, you can use :py:func:`mlflow.transformers.persist_pretrained_model()`
to download the model weights from the HuggingFace Hub and save it in the existing model
artifacts. Please refer to `Transformers flavor documentation
<../../llms/transformers/large-models.html#persist-pretrained-guide>`_
for more detailed usage.
.. code-block:: python
import mlflow.transformers
model_uri = "YOUR_MODEL_URI_LOGGED_WITH_SAVE_PRETRAINED_FALSE"
model = mlflow.transformers.persist_pretrained_model(model_uri)
mlflow.register_model(model_uri, "model_name")
.. important::
When you save the `PEFT <https://huggingface.co/docs/peft/en/index>`_ model, MLflow will
override the `save_pretrained` flag to `False` and only store the PEFT adapter weights. The
base model weights are not saved but the reference to the HuggingFace repository and
its commit hash are logged instead.
prompts: A list of prompt URIs registered in the MLflow Prompt Registry, to be associated with the model.
Each prompt URI should be in the form ``prompt:/<name>/<version>``. The prompts should be
registered in the MLflow Prompt Registry before being associated with the model.
This will create a mutual link between the model and the prompt. The associated prompts can be
seen in the model's metadata stored in the MLmodel file. From the Prompt Registry UI, you can
navigate to the model as well.
.. code-block:: python
import mlflow
prompt_template = "Hi, {name}! How are you doing today?"
# Register a prompt in the MLflow Prompt Registry
mlflow.prompts.register_prompt("my_prompt", prompt_template, description="A simple prompt")
# Log a model with the registered prompt
with mlflow.start_run():
model_info = mlflow.pyfunc.log_model(
name=MyModel(),
name="model",
prompts=["prompt:/my_prompt/1"]
)
print(model_info.prompts)
# Output: ['prompt:/my_prompt/1']
# Load the prompt
prompt = mlflow.genai.load_prompt(model_info.prompts[0])
name: Model name.
params: A dictionary of parameters to log with the model.
tags: A dictionary of tags to log with the model.
model_type: The type of the model.
step: The step at which to log the model outputs and metrics
model_id: The ID of the model.
base_model_path: Optional path to a local directory containing the base model
weights for PEFT models. When provided, only the PEFT adapter weights are
saved and the base model weights are referenced by this path instead of
being saved to the MLflow artifact. See :py:func:`save_model` for details.
kwargs: Additional arguments for :py:class:`mlflow.models.model.Model`
persist_pretrained_model(model_uri: 'str') -> 'None'
Persist Transformers pretrained model weights to the artifacts directory of the specified
model_uri. This API is primary used for updating an MLflow Model that was logged or saved
with setting save_pretrained=False. Such models cannot be registered to Databricks Workspace
Model Registry, due to the full pretrained model weights being absent in the artifacts.
Transformers models saved in this mode store only the reference to the HuggingFace Hub
repository. This API will download the model weights from the HuggingFace Hub repository
and save them in the artifacts of the given model_uri so that the model can be registered
to Databricks Workspace Model Registry.
Args:
model_uri: The URI of the existing MLflow Model of the Transformers flavor.
It must be logged/saved with save_pretrained=False.
Examples:
.. code-block:: python
import mlflow
# Saving a model with save_pretrained=False
with mlflow.start_run() as run:
model = pipeline("fill-mask", "distilroberta-base")
mlflow.transformers.log_model(
transformers_model=model, name="pipeline", save_pretrained=False
)
# The model cannot be registered to the Model Registry as it is
try:
mlflow.register_model(f"runs:/{run.info.run_id}/pipeline", "fill_mask_pipeline")
except MlflowException as e:
print(e.message)
# Use this API to persist the pretrained model weights
mlflow.transformers.persist_pretrained_model(f"runs:/{run.info.run_id}/pipeline")
# Now the model can be registered to the Model Registry
mlflow.register_model(f"runs:/{run.info.run_id}/pipeline", "fill_mask_pipeline")
save_model(transformers_model, path: 'str', processor=None, task: 'str | None' = None, torch_dtype: 'torch.dtype | None' = None, model_card=None, code_paths: 'list[str] | None' = None, mlflow_model: 'Model | None' = None, signature: 'ModelSignature | None' = None, input_example: 'ModelInputExample | None' = None, pip_requirements: 'list[str] | str | None' = None, extra_pip_requirements: 'list[str] | str | None' = None, conda_env=None, metadata: 'dict[str, Any] | None' = None, model_config: 'dict[str, Any] | None' = None, prompt_template: 'str | None' = None, save_pretrained: 'bool' = True, base_model_path: 'str | None' = None, **kwargs) -> 'None'
.. Note:: The 'transformers' MLflow Models integration is known to be compatible with ``4.43.4`` <= ``transformers`` <= ``5.14.1``. MLflow Models integrations with transformers may not succeed when used with package versions outside of this range.
Save a trained transformers model to a path on the local file system. Note that
saving transformers models with custom code (i.e. models that require
``trust_remote_code=True``) requires ``transformers >= 4.26.0``.
Args:
transformers_model:
The transformers model to save. This can be one of the following format:
1. A transformers `Pipeline` instance.
2. A dictionary that maps required components of a pipeline to the named keys
of ["model", "image_processor", "tokenizer", "feature_extractor"].
The `model` key in the dictionary must map to a value that inherits from
`PreTrainedModel`, `TFPreTrainedModel`, or `FlaxPreTrainedModel`.
All other component entries in the dictionary must support the defined task
type that is associated with the base model type configuration.
3. A string that represents a path to a local/DBFS directory containing a model
checkpoint. The directory must contain a `config.json` file that is required
for loading the transformers model. This is particularly useful when logging
a model that cannot be loaded into memory for serialization.
An example of specifying a `Pipeline` from a default pipeline instantiation:
.. code-block:: python
from transformers import pipeline
fill_pipe = pipeline("fill-mask", "distilroberta-base")
with mlflow.start_run():
mlflow.transformers.save_model(
transformers_model=fill_pipe,
path="path/to/save/model",
)
An example of specifying component-level parts of a transformers model is shown below:
.. code-block:: python
from transformers import AutoModelForMaskedLM, AutoTokenizer
architecture = "distilroberta-base"
tokenizer = AutoTokenizer.from_pretrained(architecture)
model = AutoModelForMaskedLM.from_pretrained(architecture)
with mlflow.start_run():
components = {
"model": model,
"tokenizer": tokenizer,
}
mlflow.transformers.save_model(
transformers_model=components,
path="path/to/save/model",
)
An example of specifying a local checkpoint path is shown below:
.. code-block:: python
with mlflow.start_run():
mlflow.transformers.save_model(
transformers_model="path/to/local/checkpoint",
path="path/to/save/model",
)
path: Local path destination for the serialized model to be saved.
processor: An optional ``Processor`` subclass object. Some model architectures,
particularly multi-modal types, utilize Processors to combine text
encoding and image or audio encoding in a single entrypoint.
.. Note:: If a processor is supplied when saving a model, the
model will be unavailable for loading as a ``Pipeline`` or for
usage with pyfunc inference.
task: The transformers-specific task type of the model, or MLflow inference task type.
If provided a transformers-specific task type, these strings are utilized so
that a pipeline can be created with the appropriate internal call architecture
to meet the needs of a given model.
If this argument is provided as a inference task type or not specified, the
pipeline utilities within the transformers library will be used to infer the
correct task type. If the value specified is not a supported type,
an Exception will be thrown.
torch_dtype: The Pytorch dtype applied to the model when loading back. This is useful
when you want to save the model with a specific dtype that is different from the
dtype of the model when it was trained. If not specified, the current dtype of the
model instance will be used.
model_card: An Optional `ModelCard` instance from `huggingface-hub`. If provided, the
contents of the model card will be saved along with the provided
`transformers_model`. If not provided, an attempt will be made to fetch
the card from the base pretrained model that is provided (or the one that is
included within a provided `Pipeline`).
.. Note:: In order for a ModelCard to be fetched (if not provided),
the huggingface_hub package must be installed and the version
must be >=0.10.0
code_paths: A list of local filesystem paths to Python file dependencies (or directories
containing file dependencies). These files are *prepended* to the system path when the model
is loaded. Files declared as dependencies for a given model should have relative
imports declared from a common root path if multiple files are defined with import dependencies
between them to avoid import errors when loading the model.
For a detailed explanation of ``code_paths`` functionality, recommended usage patterns and
limitations, see the
`code_paths usage guide <https://mlflow.org/docs/latest/model/dependencies.html?highlight=code_paths#saving-extra-code-with-an-mlflow-model>`_.
mlflow_model: An MLflow model object that specifies the flavor that this model is being
added to.
signature: A Model Signature object that describes the input and output Schema of the
model. The model signature can be inferred using `infer_signature` function
of `mlflow.models.signature`.
.. code-block:: python
:caption: Example
from transformers import pipeline
en_to_de = pipeline("translation_en_to_de")
data = "MLflow is great!"
mlflow.transformers.save_model(
transformers_model=en_to_de,
path="/path/to/save/model",
input_example=data,
)
loaded = mlflow.pyfunc.load_model("/path/to/save/model")
print(loaded.predict(data))
# MLflow ist großartig!
If an input_example is provided and the signature is not, a signature will
be inferred automatically and applied to the MLmodel file iff the
pipeline type is a text-based model (NLP). If the pipeline type is not
a supported type, this inference functionality will not function correctly
and a warning will be issued. In order to ensure that a precise signature
is logged, it is recommended to explicitly provide one.
input_example: one or several instances of valid model input. The input example is used
as a hint of what data to feed the model. It will be converted to a Pandas
DataFrame and then serialized to json using the Pandas split-oriented
format, or a numpy array where the example will be serialized to json
by converting it to a list. Bytes are base64-encoded. When the ``signature`` parameter is
``None``, the input example is used to infer a model signature.
pip_requirements: Either an iterable of pip requirement strings
(e.g. ``["transformers", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes the environment this model should be run in. If ``None``, a default list of requirements
is inferred by :func:`mlflow.models.infer_pip_requirements` from the current software environment.
If the requirement inference fails, it falls back to using `get_default_pip_requirements`.
Both requirements and constraints are automatically parsed and written to ``requirements.txt`` and
``constraints.txt`` files, respectively, and stored as part of the model. Requirements are also
written to the ``pip`` section of the model's conda environment (``conda.yaml``) file.
extra_pip_requirements: Either an iterable of pip
requirement strings
(e.g. ``["pandas", "-r requirements.txt", "-c constraints.txt"]``) or the string path to
a pip requirements file on the local filesystem (e.g. ``"requirements.txt"``). If provided, this
describes additional pip requirements that are appended to a default set of pip requirements
generated automatically based on the user's current software environment. Both requirements and
constraints are automatically parsed and written to ``requirements.txt`` and ``constraints.txt``
files, respectively, and stored as part of the model. Requirements are also written to the ``pip``
section of the model's conda environment (``conda.yaml``) file.
.. warning::
The following arguments can't be specified at the same time:
- ``conda_env``
- ``pip_requirements``
- ``extra_pip_requirements``
`This example <https://github.com/mlflow/mlflow/blob/master/examples/pip_requirements/pip_requirements.py>`_ demonstrates how to specify pip requirements using
``pip_requirements`` and ``extra_pip_requirements``.
conda_env: Either a dictionary representation of a Conda environment or the path to a conda
environment yaml file. If provided, this describes the environment this model should be run in.
At a minimum, it should specify the dependencies contained in `get_default_conda_env()`.
If ``None``, a conda environment with pip requirements inferred by
:func:`mlflow.models.infer_pip_requirements` is added
to the model. If the requirement inference fails, it falls back to using
`get_default_pip_requirements`. pip requirements from ``conda_env`` are written to a pip
``requirements.txt`` file and the full conda environment is written to ``conda.yaml``.
The following is an *example* dictionary representation of a conda environment::
{
"name": "mlflow-env",
"channels": ["conda-forge"],
"dependencies": [
"python=3.8.15",
{
"pip": [
"transformers==x.y.z"
],
},
],
}
metadata: Custom metadata dictionary passed to the model and stored in the MLmodel file.
model_config:
A dict of valid overrides that can be applied to a pipeline instance during inference.
These arguments are used exclusively for the case of loading the model as a ``pyfunc``
Model or for use in Spark.
These values are not applied to a returned Pipeline from a call to
``mlflow.transformers.load_model()``
.. Warning:: If the key provided is not compatible with either the
Pipeline instance for the task provided or is not a valid
override to any arguments available in the Model, an
Exception will be raised at runtime. It is very important
to validate the entries in this dictionary to ensure
that they are valid prior to saving or logging.
An example of providing overrides for a question generation model:
.. code-block:: python
from transformers import pipeline, AutoTokenizer
task = "text-generation"
architecture = "gpt2"
sentence_pipeline = pipeline(
task=task,
tokenizer=AutoTokenizer.from_pretrained(architecture),
model=architecture,
)
# Validate that the overrides function
prompts = ["Generative models are", "I'd like a coconut so that I can"]
# validation of config prior to save or log
model_config = {
"top_k": 2,
"num_beams": 5,
"max_length": 30,
"temperature": 0.62,
"top_p": 0.85,
"repetition_penalty": 1.15,
}
# Verify that no exceptions are thrown
sentence_pipeline(prompts, **model_config)
mlflow.transformers.save_model(
transformers_model=sentence_pipeline,
path="/path/for/model",
task=task,
model_config=model_config,
)
prompt_template: A string that, if provided, will be used to format the user's input prior
to inference. The string should contain a single placeholder, ``{prompt}``, which will be
replaced with the user's input. For example: ``"Answer the following question. Q: {prompt} A:"``.
Currently, only the following pipeline types are supported:
- `feature-extraction <https://huggingface.co/transformers/main_classes/pipelines.html#transformers.FeatureExtractionPipeline>`_
- `fill-mask <https://huggingface.co/transformers/main_classes/pipelines.html#transformers.FillMaskPipeline>`_
- `summarization <https://huggingface.co/transformers/main_classes/pipelines.html#transformers.SummarizationPipeline>`_
- `text2text-generation <https://huggingface.co/transformers/main_classes/pipelines.html#transformers.Text2TextGenerationPipeline>`_
- `text-generation <https://huggingface.co/transformers/main_classes/pipelines.html#transformers.TextGenerationPipeline>`_
The following example shows how to log a text-generation pipeline with a prompt template and
use it via the ``python_function`` (pyfunc) flavor:
.. code-block:: python
import mlflow
from transformers import pipeline
# Initialize a text-generation pipeline
generator = pipeline("text-generation", model="gpt2")
# Define a prompt template. The ``{prompt}`` placeholder will be replaced
# with the raw user input at inference time.
prompt_template = "Answer the following question concisely.\n\nQ: {prompt}\nA:"
example_prompt = "What is MLflow?"
# Log the model with the prompt template and an input example
with mlflow.start_run():
model_info = mlflow.transformers.log_model(
transformers_model=generator,
name="qa_text_generator",
prompt_template=prompt_template,
input_example=example_prompt,
)
# Load the model back as a pyfunc model
loaded_model = mlflow.pyfunc.load_model(model_info.model_uri)
# The input to ``predict`` is the raw question string; the prompt template
# is applied internally before calling the underlying transformers pipeline.
loaded_model.predict("What is experiment tracking?")
save_pretrained: If set to ``False``, MLflow will not save the Transformer model weight files,
instead only saving the reference to the HuggingFace Hub model repository and its commit hash.
This is useful when you load the pretrained model from HuggingFace Hub and want to log or save
it to MLflow without modifying the model weights. In such case, specifying this flag to
``False`` will save the storage space and reduce time to save the model. Please refer to the
`Storage-Efficient Model Logging
<../../llms/transformers/large-models.html#transformers-save-pretrained-guide>`_ for more detailed
usage.
.. warning::
If the model is saved with ``save_pretrained`` set to ``False``, the model cannot be
registered to the MLflow Model Registry. In order to convert the model to the one that
can be registered, you can use :py:func:`mlflow.transformers.persist_pretrained_model()`
to download the model weights from the HuggingFace Hub and save it in the existing model
artifacts. Please refer to `Transformers flavor documentation
<../../llms/transformers/large-models.html#persist-pretrained-guide>`_
for more detailed usage.
.. code-block:: python
import mlflow.transformers
model_uri = "YOUR_MODEL_URI_LOGGED_WITH_SAVE_PRETRAINED_FALSE"
model = mlflow.transformers.persist_pretrained_model(model_uri)
mlflow.register_model(model_uri, "model_name")
.. important::
When you save the `PEFT <https://huggingface.co/docs/peft/en/index>`_ model, MLflow will
override the `save_pretrained` flag to `False` and only store the PEFT adapter weights. The
base model weights are not saved but the reference to the HuggingFace repository and
its commit hash are logged instead.
base_model_path: Optional path to a local directory containing the base model
weights for PEFT models. When provided, only the PEFT adapter weights are
saved and the base model weights are referenced by this path instead of
being saved to the MLflow artifact. This is useful for:
- Air-gapped environments where the base model cannot be downloaded from
HuggingFace Hub.
- Avoiding duplication of large base model weights.
At load time, the base model will be loaded from this path and the PEFT
adapter will be applied on top. The path must point to a valid directory
containing the base model at both save and load time.
.. code-block:: python
from peft import get_peft_model, LoraConfig
from transformers import AutoModelForCausalLM, AutoTokenizer
base_path = "/shared/models/llama-7b"
base_model = AutoModelForCausalLM.from_pretrained(base_path)
tokenizer = AutoTokenizer.from_pretrained(base_path)
peft_model = get_peft_model(base_model, LoraConfig(...))
with mlflow.start_run():
mlflow.transformers.save_model(
transformers_model={"model": peft_model, "tokenizer": tokenizer},
path="path/to/save",
base_model_path=base_path,
)
kwargs: Optional additional configurations for transformers serialization.
DATA
AudioInput = str | bytes | numpy.ndarray
BAD_REQUEST = 4
DEFAULT_AWAIT_MAX_SLEEP_SECONDS = 300
FLAVOR_NAME = 'transformers'
INVALID_PARAMETER_VALUE = 1000
LOG_MODEL_PARAM_DOCS = ParamDocs({'name': 'Model name.', 'conda_env': ...
MLFLOW_DEFAULT_PREDICTION_DEVICE = 'MLFLOW_DEFAULT_PREDICTION_DEVICE'
MLFLOW_HUGGINGFACE_DEVICE_MAP_STRATEGY = 'MLFLOW_HUGGINGFACE_DEVICE_MA...
MLFLOW_HUGGINGFACE_USE_DEVICE_MAP = 'MLFLOW_HUGGINGFACE_USE_DEVICE_MAP...
MLFLOW_HUGGINGFACE_USE_LOW_CPU_MEM_USAGE = 'MLFLOW_HUGGINGFACE_USE_LOW...
MLFLOW_INPUT_EXAMPLE_INFERENCE_TIMEOUT = 'MLFLOW_INPUT_EXAMPLE_INFEREN...
MLMODEL_FILE_NAME = 'MLmodel'
ModelInputExample = typing.Union[pandas.core.frame.DataFrame, numpy......
RESOURCE_DOES_NOT_EXIST = 3002
TYPE_CHECKING = False
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\transformers\__init__.py
mlflow.txtai
Error rendering doc: No module named 'mlflow_txtai'
mlflow.types
Python Library Documentation: package mlflow.types in mlflow
NAME
mlflow.types
DESCRIPTION
The :py:mod:`mlflow.types` module defines data types and utilities to be used by other mlflow
components to describe interface independent of other frameworks or languages.
PACKAGE CONTENTS
agent
chat
llm
responses
responses_helpers
schema
type_hints
utils
CLASSES
builtins.object
mlflow.types.schema.ColSpec
mlflow.types.schema.ParamSchema
mlflow.types.schema.ParamSpec
mlflow.types.schema.Schema
mlflow.types.schema.TensorSpec
enum.Enum(builtins.object)
mlflow.types.schema.DataType
class ColSpec(builtins.object)
| ColSpec(type: 'ALLOWED_DTYPES', name: 'str | None' = None, required: 'bool' = True)
|
| Specification of name and type of a single column in a dataset.
|
| Methods defined here:
|
| __eq__(self, other) -> 'bool'
| Return self==value.
|
| __init__(self, type: 'ALLOWED_DTYPES', name: 'str | None' = None, required: 'bool' = True)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self) -> 'str'
| Return repr(self).
|
| to_dict(self) -> 'dict[str, Any]'
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_json_dict(**kwargs)
| Deserialize from a json loaded dictionary.
| The dictionary is expected to contain `type` and
| optional `name` and `required` keys.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| required
| Whether this column is required.
|
| type
| The column data type.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| name
| The column name or None if the columns is unnamed.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __hash__ = None
class DataType(enum.Enum)
| DataType(*values)
|
| MLflow data types.
|
| Method resolution order:
| DataType
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| binary = binary
|
| boolean = boolean
|
| datetime = datetime
|
| double = double
|
| float = float
|
| integer = integer
|
| long = long
|
| string = string
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Static methods inherited from enum.EnumType:
|
| __contains__(value)
| Return True if `value` is in `cls`.
|
| `value` is in `cls` if:
| 1) `value` is a member of `cls`, or
| 2) `value` is the value of one of the `cls`'s members.
|
| __getitem__(name)
| Return the member matching `name`.
|
| __iter__()
| Return members in definition order.
|
| __len__()
| Return the number of members (no aliases)
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class ParamSchema(builtins.object)
| ParamSchema(params: 'list[ParamSpec]')
|
| Specification of parameters applicable to the model.
| ParamSchema is represented as a list of :py:class:`ParamSpec`.
|
| Methods defined here:
|
| __eq__(self, other) -> 'bool'
| Return self==value.
|
| __init__(self, params: 'list[ParamSpec]')
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __repr__(self) -> 'str'
| Return repr(self).
|
| to_dict(self) -> 'list[dict[str, Any]]'
| Serialize into a jsonable dictionary.
|
| to_json(self) -> 'str'
| Serialize into json string.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_json(json_str: 'str')
| Deserialize from a json string.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| params
| Representation of ParamSchema as a list of ParamSpec.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __hash__ = None
class ParamSpec(builtins.object)
| ParamSpec(name: 'str', dtype: 'DataType | Object | str', default: 'Any', shape: 'tuple[int, ...] | None' = None)
|
| Specification used to represent parameters for the model.
|
| Methods defined here:
|
| __eq__(self, other) -> 'bool'
| Return self==value.
|
| __init__(self, name: 'str', dtype: 'DataType | Object | str', default: 'Any', shape: 'tuple[int, ...] | None' = None)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self) -> 'str'
| Return repr(self).
|
| to_dict(self) -> 'ParamSpecTypedDict'
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_json_dict(**kwargs)
| Deserialize from a json loaded dictionary.
| The dictionary is expected to contain `name`, `type` and `default` keys.
|
| validate_param_spec(value: 'Any', param_spec: "'ParamSpec'")
|
| validate_type_and_shape(spec: 'str', value: 'Any', value_type: 'DataType | Object', shape: 'tuple[int, ...] | None')
| Validate that the value has the expected type and shape.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| default
| Default value of the parameter.
|
| dtype
| The parameter data type.
|
| name
| The name of the parameter.
|
| shape
| The parameter shape.
| If shape is None, the parameter is a scalar.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| ParamSpecTypedDict = <class 'mlflow.types.schema.ParamSpec.ParamSpecTy...
|
| __hash__ = None
class Schema(builtins.object)
| Schema(inputs: 'list[ColSpec | TensorSpec]')
|
| Specification of a dataset.
|
| Schema is represented as a list of :py:class:`ColSpec` or :py:class:`TensorSpec`. A combination
| of `ColSpec` and `TensorSpec` is not allowed.
|
| The dataset represented by a schema can be named, with unique non empty names for every input.
| In the case of :py:class:`ColSpec`, the dataset columns can be unnamed with implicit integer
| index defined by their list indices.
| Combination of named and unnamed data inputs are not allowed.
|
| Methods defined here:
|
| __eq__(self, other) -> 'bool'
| Return self==value.
|
| __init__(self, inputs: 'list[ColSpec | TensorSpec]')
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __repr__(self) -> 'str'
| Return repr(self).
|
| as_spark_schema(self)
| Convert to Spark schema. If this schema is a single unnamed column, it is converted
| directly the corresponding spark data type, otherwise it's returned as a struct (missing
| column names are filled with an integer sequence).
| Unsupported by TensorSpec.
|
| has_input_names(self) -> 'bool'
| Return true iff this schema declares names, false otherwise.
|
| input_dict(self) -> 'dict[str, ColSpec | TensorSpec]'
| Maps column names to inputs, iff this schema declares names.
|
| input_names(self) -> 'list[str | int]'
| Get list of data names or range of indices if the schema has no names.
|
| input_types(self) -> 'list[DataType | np.dtype | Array | Object]'
| Get types for each column in the schema.
|
| input_types_dict(self) -> 'dict[str, DataType | np.dtype | Array | Object]'
| Maps column names to types, iff this schema declares names.
|
| is_tensor_spec(self) -> 'bool'
| Return true iff this schema is specified using TensorSpec
|
| numpy_types(self) -> 'list[np.dtype]'
| Convenience shortcut to get the datatypes as numpy types.
|
| optional_input_names(self) -> 'list[str | int]'
| Get list of optional data names or range of indices if schema has no names.
|
| pandas_types(self) -> 'list[np.dtype]'
| Convenience shortcut to get the datatypes as pandas types. Unsupported by TensorSpec.
|
| required_input_names(self) -> 'list[str | int]'
| Get list of required data names or range of indices if schema has no names.
|
| to_dict(self) -> 'list[dict[str, Any]]'
| Serialize into a jsonable dictionary.
|
| to_json(self) -> 'str'
| Serialize into json string.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_json(json_str: 'str')
| Deserialize from a json string.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| inputs
| Representation of a dataset that defines this schema.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __hash__ = None
class TensorSpec(builtins.object)
| TensorSpec(type: 'np.dtype', shape: 'tuple[int, ...] | list[int]', name: 'str | None' = None)
|
| Specification used to represent a dataset stored as a Tensor.
|
| Methods defined here:
|
| __eq__(self, other) -> 'bool'
| Return self==value.
|
| __init__(self, type: 'np.dtype', shape: 'tuple[int, ...] | list[int]', name: 'str | None' = None)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self) -> 'str'
| Return repr(self).
|
| to_dict(self) -> 'dict[str, Any]'
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_json_dict(**kwargs)
| Deserialize from a json loaded dictionary.
| The dictionary is expected to contain `type` and `tensor-spec` keys.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| name
| The tensor name or None if the tensor is unnamed.
|
| required
| Whether this tensor is required.
|
| shape
| The tensor shape
|
| type
| A unique character code for each of the 21 different numpy built-in types.
| See https://numpy.org/devdocs/reference/generated/numpy.dtype.html#numpy.dtype for details.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __hash__ = None
DATA
__all__ = ['Schema', 'ColSpec', 'DataType', 'TensorSpec', 'ParamSchema...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\types\__init__.py
mlflow.update_assessment
Python Library Documentation: function update_assessment in module mlflow.tracing.assessment
update_assessment(trace_id: str, assessment_id: str, assessment: mlflow.entities.assessment.Assessment) -> mlflow.entities.assessment.Assessment
Updates an existing expectation (ground truth) in a Trace.
Args:
trace_id: The ID of the trace.
assessment_id: The ID of the expectation or feedback assessment to update.
assessment: The updated assessment.
Returns:
:py:class:`~mlflow.entities.Assessment`: The updated feedback or expectation assessment.
Example:
The following code updates an existing expectation with a new value.
To update other fields, provide the corresponding parameters.
.. code-block:: python
import mlflow
from mlflow.entities import Expectation, ExpectationValue
# Create an expectation with value 42.
response = mlflow.log_assessment(
trace_id="1234",
assessment=Expectation(name="expected_answer", value=42),
)
assessment_id = response.assessment_id
# Update the expectation with a new value 43.
mlflow.update_assessment(
trace_id="1234",
assessment_id=assessment.assessment_id,
assessment=Expectation(name="expected_answer", value=43),
)
mlflow.update_current_trace
Python Library Documentation: function update_current_trace in module mlflow.tracing.fluent
update_current_trace(tags: 'dict[str, str] | None' = None, metadata: 'dict[str, str] | None' = None, client_request_id: 'str | None' = None, request_preview: 'str | None' = None, response_preview: 'str | None' = None, state: 'TraceState | str | None' = None, model_id: 'str | None' = None, session_id: 'str | None' = None, user: 'str | None' = None)
Update the current active trace with the given options.
Args:
tags: A dictionary of tags to update the trace with Tags are designed for mutable values,
that can be updated after the trace is created via MLflow UI or API.
metadata: A dictionary of metadata to update the trace with. Metadata cannot be updated
once the trace is logged. It is suitable for recording immutable values like the
git hash of the application version that produced the trace.
client_request_id: Client supplied request ID to associate with the trace. This is
useful for linking the trace back to a specific request in your application or
external system. If None, the client request ID is not updated.
request_preview: A preview of the request to be shown in the Trace list view in the UI.
By default, MLflow will truncate the trace request naively by limiting the length.
This parameter allows you to specify a custom preview string.
response_preview: A preview of the response to be shown in the Trace list view in the UI.
By default, MLflow will truncate the trace response naively by limiting the length.
This parameter allows you to specify a custom preview string.
state: The state to set on the trace. Can be a TraceState enum value or string.
Only "OK" and "ERROR" are allowed. This overrides the overall trace state without
affecting the status of the current span.
model_id: The ID of the model to associate with the trace. If not set, the active
model ID is associated with the trace.
session_id: Session ID to associate with the trace. Stored as metadata under the
``mlflow.trace.session`` key.
user: User identifier to associate with the trace. Stored as metadata under the
``mlflow.trace.user`` key.
Example:
You can use this function either within a function decorated with ``@mlflow.trace`` or
within the scope of the `with mlflow.start_span` context manager. If there is no active
trace found, this function will raise an exception.
Using within a function decorated with `@mlflow.trace`:
.. code-block:: python
@mlflow.trace
def my_func(x):
mlflow.update_current_trace(tags={"fruit": "apple"}, client_request_id="req-12345")
return x + 1
Using within the ``with mlflow.start_span`` context manager:
.. code-block:: python
with mlflow.start_span("span"):
mlflow.update_current_trace(tags={"fruit": "apple"}, client_request_id="req-12345")
Updating user, session, and source information of the trace:
.. code-block:: python
mlflow.update_current_trace(
session_id="session-4f855da00427",
user="user-id-cc156f29bcfb",
metadata={
"mlflow.source.name": "inference.py",
"mlflow.source.git.commit": "1234567890",
"mlflow.source.git.repoURL": "https://github.com/mlflow/mlflow",
},
)
Updating request preview:
.. code-block:: python
import mlflow
import openai
@mlflow.trace
def predict(messages: list[dict]) -> str:
# Customize the request preview to show the first and last messages
custom_preview = f"{messages[0]['content'][:10]} ... {messages[-1]['content'][:10]}"
mlflow.update_current_trace(request_preview=custom_preview)
# Call the model
response = openai.chat.completions.create(
model="o4-mini",
messages=messages,
)
return response.choices[0].message.content
messages = [
{"role": "user", "content": "Hi, how are you?"},
{"role": "assistant", "content": "I'm good, thank you!"},
{"role": "user", "content": "What's your name?"},
# ... (long message history)
{"role": "assistant", "content": "Bye!"},
]
predict(messages)
# The request preview rendered in the UI will be:
# "Hi, how are you? ... Bye!"
mlflow.update_workspace
Python Library Documentation: function update_workspace in module mlflow.tracking._workspace.fluent
update_workspace(name: 'str', description: 'str | None' = None, default_artifact_root: 'str | None' = None, trace_archival_config: 'TraceArchivalConfig | None' = None) -> 'Workspace'
.. Note:: Experimental: This function may change or be removed in a future release without warning.
Update metadata for an existing workspace.
Args:
name: The name of the workspace to update.
description: New description, or ``None`` to leave unchanged.
default_artifact_root: New artifact root URI, empty string to clear, or ``None``.
trace_archival_config: Optional archival settings; use ``""`` to clear, ``None`` to keep.
Returns:
The updated workspace.
Raises:
MlflowException: If the workspace does not exist or no artifact root available.
mlflow.utils
Python Library Documentation: package mlflow.utils in mlflow
NAME
mlflow.utils
PACKAGE CONTENTS
_capture_modules
_capture_transformers_modules
_spark_utils
_unity_catalog_oss_utils
_unity_catalog_utils
annotations
arguments_utils
async_logging (package)
autologging_utils (package)
checkpoint_utils
class_utils
cli_args
conda
credentials
crypto
data_utils
databricks_sql_warehouse
databricks_tracing_utils
databricks_utils
docstring_utils
doctor
download_cloud_file_chunk
env_manager
env_pack
environment
exception_utils
file_utils
git_utils
gorilla
huggingface_utils
import_hooks (package)
jsonpath_utils
lazy_load
logging_utils
mime_type_utils
mlflow_tags
model_catalog (package)
model_utils
name_utils
nfs_on_spark
openai_utils
os
oss_registry_utils
plugins
process
promptlab_utils
proto_json_utils
provider_filter
providers
request_utils
requirements_utils
rest_utils
search_logged_model_utils
search_utils
semver_utils
server_cli_utils
spark_utils
string_utils
thread_utils
time
timeout
uri
uv_utils
validation
virtualenv
warnings_utils
workspace_context
workspace_utils
yaml_utils
CLASSES
builtins.dict(builtins.object)
AttrDict
class AttrDict(builtins.dict)
| Dict-like object that exposes its keys as attributes.
|
| Examples
| --------
| >>> d = AttrDict({"a": 1, "b": 2})
| >>> d.a
| 1
| >>> d = AttrDict({"a": 1, "b": {"c": 3, "d": 4}})
| >>> d.b.c
| 3
| >>> d.c = 5
| >>> d.c
| 5
|
| Method resolution order:
| AttrDict
| builtins.dict
| builtins.object
|
| Methods defined here:
|
| __delattr__(self, key)
| Implement delattr(self, name).
|
| __getattr__(self, attr)
|
| __setattr__(self, attr, value)
| Implement setattr(self, name, value).
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.dict:
|
| __contains__(self, key, /)
| True if the dictionary has the specified key, else False.
|
| __delitem__(self, key, /)
| Delete self[key].
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __gt__(self, value, /)
| Return self>value.
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __ior__(self, value, /)
| Return self|=value.
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __or__(self, value, /)
| Return self|value.
|
| __repr__(self, /)
| Return repr(self).
|
| __reversed__(self, /)
| Return a reverse iterator over the dict keys.
|
| __ror__(self, value, /)
| Return value|self.
|
| __setitem__(self, key, value, /)
| Set self[key] to value.
|
| __sizeof__(...)
| D.__sizeof__() -> size of D in memory, in bytes
|
| clear(...)
| D.clear() -> None. Remove all items from D.
|
| copy(...)
| D.copy() -> a shallow copy of D
|
| get(self, key, default=None, /)
| Return the value for key if key is in the dictionary, else default.
|
| items(...)
| D.items() -> a set-like object providing a view on D's items
|
| keys(...)
| D.keys() -> a set-like object providing a view on D's keys
|
| pop(...)
| D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
|
| If the key is not found, return the default if given; otherwise,
| raise a KeyError.
|
| popitem(self, /)
| Remove and return a (key, value) pair as a 2-tuple.
|
| Pairs are returned in LIFO (last-in, first-out) order.
| Raises KeyError if the dict is empty.
|
| setdefault(self, key, default=None, /)
| Insert key with a value of default if key is not in the dictionary.
|
| Return the value for key if key is in the dictionary, else default.
|
| update(...)
| D.update([E, ]**F) -> None. Update D from dict/iterable E and F.
| If E is present and has a .keys() method, then does: for k in E: D[k] = E[k]
| If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v
| In either case, this is followed by: for k in F: D[k] = F[k]
|
| values(...)
| D.values() -> an object providing a view on D's values
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.dict:
|
| __class_getitem__(...)
| See PEP 585
|
| fromkeys(iterable, value=None, /)
| Create a new dictionary with keys from iterable and values set to value.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.dict:
|
| __new__(*args, **kwargs) class method of builtins.dict
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from builtins.dict:
|
| __hash__ = None
FUNCTIONS
check_port_connectivity()
chunk_list(l, chunk_size)
find_free_port()
Find free socket port on local machine.
get_major_minor_py_version(py_version)
get_parent_module(module)
get_results_from_paginated_fn(paginated_fn, max_results_per_page, max_results=None)
Gets results by calling the ``paginated_fn`` until either no more results remain or
the specified ``max_results`` threshold has been reached.
Args:
paginated_fn: This function is expected to take in the number of results to retrieve
per page and a pagination token, and return a PagedList object.
max_results_per_page: The maximum number of results to retrieve per page.
max_results: The maximum number of results to retrieve overall. If unspecified,
all results will be retrieved.
Returns:
Returns a list of entities, as determined by the paginated_fn parameter, with no more
entities than specified by max_results.
is_iterator(obj)
Args:
obj: Any object.
Returns:
Boolean representing whether or not 'obj' is an iterator.
is_port_available(port: int, host: str = '127.0.0.1') -> bool
Check if a port is available for binding.
Args:
port: The port number to check.
host: The host address to check. Defaults to localhost.
Returns:
True if the port is available, False if it's already in use.
is_uuid(s: str) -> bool
Returns True if the specified string is a UUID, False otherwise.
merge_dicts(dict_a, dict_b, raise_on_duplicates=True)
This function takes two dictionaries and returns one singular merged dictionary.
Args:
dict_a: The first dictionary.
dict_b: The second dictionary.
raise_on_duplicates: If True, the function raises ValueError if there are duplicate keys.
Otherwise, duplicate keys in `dict_b` will override the ones in `dict_a`.
Returns:
A merged dictionary.
reraise(tp, value, tb=None)
DATA
PYTHON_VERSION = '3.12.6'
version_info = sys.version_info(major=3, minor=12, micro=6, releaselev...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\utils\__init__.py
mlflow.validate_evaluation_results
Python Library Documentation: function validate_evaluation_results in module mlflow.models.evaluation.validation
validate_evaluation_results(validation_thresholds: dict[str, mlflow.models.evaluation.validation.MetricThreshold], candidate_result: mlflow.models.evaluation.base.EvaluationResult, baseline_result: mlflow.models.evaluation.base.EvaluationResult | None = None)
Validate the evaluation result from one model (candidate) against another
model (baseline). If the candidate results do not meet the validation
thresholds, an ModelValidationFailedException will be raised.
.. note::
This API is a replacement for the deprecated model validation
functionality in the :py:func:`mlflow.evaluate` API.
Args:
validation_thresholds: A dictionary of metric name to
:py:class:`mlflow.models.MetricThreshold` used for model validation.
Each metric name must either be the name of a builtin metric or the
name of a metric defined in the ``extra_metrics`` parameter.
candidate_result: The evaluation result of the candidate model.
Returned by the :py:func:`mlflow.evaluate` API.
baseline_result: The evaluation result of the baseline model.
Returned by the :py:func:`mlflow.evaluate` API.
If set to None, the candidate model result will be
compared against the threshold values directly.
Code Example:
.. code-block:: python
:caption: Example of Model Validation
import mlflow
from mlflow.models import MetricThreshold
thresholds = {
"accuracy_score": MetricThreshold(
# accuracy should be >=0.8
threshold=0.8,
# accuracy should be at least 5 percent greater than baseline model accuracy
min_absolute_change=0.05,
# accuracy should be at least 0.05 greater than baseline model accuracy
min_relative_change=0.05,
greater_is_better=True,
),
}
# Get evaluation results for the candidate model
candidate_result = mlflow.evaluate(
model="<YOUR_CANDIDATE_MODEL_URI>",
data=eval_dataset,
targets="ground_truth",
model_type="classifier",
)
# Get evaluation results for the baseline model
baseline_result = mlflow.evaluate(
model="<YOUR_BASELINE_MODEL_URI>",
data=eval_dataset,
targets="ground_truth",
model_type="classifier",
)
# Validate the results
mlflow.validate_evaluation_results(
thresholds,
candidate_result,
baseline_result,
)
See `the Model Validation documentation
<../../models/index.html#performing-model-validation>`_ for more details.
mlflow.version
Python Library Documentation: module mlflow.version in mlflow
NAME
mlflow.version - # Copyright 2018 Databricks, Inc.
FUNCTIONS
is_release_version()
DATA
IS_FULL_MLFLOW = True
IS_MLFLOW_SKINNY = False
IS_TRACING_SDK_ONLY = False
VERSION = '3.15.0'
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\version.py
mlflow.xgboost
Python Library Documentation: package mlflow.xgboost in mlflow
NAME
mlflow.xgboost
DESCRIPTION
The ``mlflow.xgboost`` module provides an API for logging and loading XGBoost models.
This module exports XGBoost models with the following flavors:
XGBoost (native) format
This is the main flavor that can be loaded back into XGBoost.
:py:mod:`mlflow.pyfunc`
Produced for use by generic pyfunc-based deployment tools and batch inference.
.. _xgboost.Booster:
https://xgboost.readthedocs.io/en/latest/python/python_api.html#xgboost.Booster
.. _xgboost.Booster.save_model:
https://xgboost.readthedocs.io/en/latest/python/python_api.html#xgboost.Booster.save_model
.. _xgboost.train:
https://xgboost.readthedocs.io/en/latest/python/python_api.html#xgboost.train
.. _scikit-learn API:
https://xgboost.readthedocs.io/en/latest/python/python_api.html#module-xgboost.sklearn
PACKAGE CONTENTS
_autolog
DATA
DEFAULT_AWAIT_MAX_SLEEP_SECONDS = 300
ENSURE_AUTOLOGGING_ENABLED_TEXT = 'please ensure that autologging is e...
FLAVOR_NAME = 'xgboost'
INPUT_EXAMPLE_SAMPLE_ROWS = 5
LOG_MODEL_PARAM_DOCS = ParamDocs({'name': 'Model name.', 'conda_env': ...
MLFLOW_DATASET_CONTEXT = 'mlflow.data.context'
MLMODEL_FILE_NAME = 'MLmodel'
ModelInputExample = typing.Union[pandas.core.frame.DataFrame, numpy......
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\mlflow\xgboost\__init__.py