code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def search_logged_models(
experiment_ids: Optional[list[str]] = None,
filter_string: Optional[str] = None,
datasets: Optional[list[dict[str, str]]] = None,
max_results: Optional[int] = None,
order_by: Optional[list[dict[str, Any]]] = None,
output_format: Literal["pandas", "list"] = "pandas",
) -... |
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:
... | search_logged_models | python | mlflow/mlflow | mlflow/tracking/fluent.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/fluent.py | Apache-2.0 |
def get_artifact_uri(artifact_path: Optional[str] = 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
art... |
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 ac... | get_artifact_uri | python | mlflow/mlflow | mlflow/tracking/fluent.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/fluent.py | Apache-2.0 |
def search_runs(
experiment_ids: Optional[list[str]] = None,
filter_string: str = "",
run_view_type: int = ViewType.ACTIVE_ONLY,
max_results: int = SEARCH_MAX_RESULTS_PANDAS,
order_by: Optional[list[str]] = None,
output_format: str = "pandas",
search_all_experiments: bool = False,
experi... |
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
... | search_runs | python | mlflow/mlflow | mlflow/tracking/fluent.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/fluent.py | Apache-2.0 |
def _get_active_model_id_from_env() -> Optional[str]:
"""
Get the active model ID from environment variables, with proper precedence handling.
This utility function reads the active model ID from environment variables with the following
precedence order:
1. MLFLOW_ACTIVE_MODEL_ID (public variable) ... |
Get the active model ID from environment variables, with proper precedence handling.
This utility function reads the active model ID from environment variables with the following
precedence order:
1. MLFLOW_ACTIVE_MODEL_ID (public variable) - takes precedence if set
2. _MLFLOW_ACTIVE_MODEL_ID (leg... | _get_active_model_id_from_env | python | mlflow/mlflow | mlflow/tracking/fluent.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/fluent.py | Apache-2.0 |
def _set_active_model_id(model_id: str, set_by_user: bool = False) -> None:
"""
Set the active model ID in the active model context and update the
corresponding environment variable. This should only be used when
we know the LoggedModel with the model_id exists.
This function should be used inside M... |
Set the active model ID in the active model context and update the
corresponding environment variable. This should only be used when
we know the LoggedModel with the model_id exists.
This function should be used inside MLflow to set the active model
while not blocking other code execution.
| _set_active_model_id | python | mlflow/mlflow | mlflow/tracking/fluent.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/fluent.py | Apache-2.0 |
def _get_active_model_id_global() -> Optional[str]:
"""
Get the active model ID from the global context by checking all threads.
This is useful when we need to get the active_model_id set by a different thread.
"""
# if the active model ID is set in the current thread, always use it
if model_id_... |
Get the active model ID from the global context by checking all threads.
This is useful when we need to get the active_model_id set by a different thread.
| _get_active_model_id_global | python | mlflow/mlflow | mlflow/tracking/fluent.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/fluent.py | Apache-2.0 |
def 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 temp... |
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 ... | clear_active_model | python | mlflow/mlflow | mlflow/tracking/fluent.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/fluent.py | Apache-2.0 |
def _converter_requires(module_name: str):
"""Wrapper function that checks if specified `module_name` is already imported before
invoking wrapped function.
"""
def decorator(func):
def wrapper(x):
if not _is_module_imported(module_name):
return x
return ... | Wrapper function that checks if specified `module_name` is already imported before
invoking wrapped function.
| _converter_requires | python | mlflow/mlflow | mlflow/tracking/metric_value_conversion_utils.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/metric_value_conversion_utils.py | Apache-2.0 |
def compress_image_size(
image: "PIL.Image.Image", max_size: Optional[int] = COMPRESSED_IMAGE_SIZE
) -> "PIL.Image.Image":
"""
Scale the image to fit within a square with length `max_size` while maintaining
the aspect ratio.
"""
# scale the image to max(width, height) <= compressed_file_max_size... |
Scale the image to fit within a square with length `max_size` while maintaining
the aspect ratio.
| compress_image_size | python | mlflow/mlflow | mlflow/tracking/multimedia.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/multimedia.py | Apache-2.0 |
def convert_to_pil_image(image: Union["numpy.ndarray", list]) -> "PIL.Image.Image":
"""
Convert a numpy array to a PIL image.
"""
import numpy as np
try:
from PIL import Image
except ImportError as exc:
raise ImportError(
"Pillow is required to serialize a numpy arra... |
Convert a numpy array to a PIL image.
| convert_to_pil_image | python | mlflow/mlflow | mlflow/tracking/multimedia.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/multimedia.py | Apache-2.0 |
def register_entrypoints(self):
"""Register tracking stores provided by other packages"""
for entrypoint in get_entry_points(self.group_name):
try:
self.register(entrypoint.name, entrypoint.load())
except (AttributeError, ImportError) as exc:
warni... | Register tracking stores provided by other packages | register_entrypoints | python | mlflow/mlflow | mlflow/tracking/registry.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/registry.py | Apache-2.0 |
def get_store_builder(self, store_uri):
"""Get a store from the registry based on the scheme of store_uri
Args:
store_uri: The store URI. If None, it will be inferred from the environment. This
URI is used to select which tracking store implementation to instantiate
... | Get a store from the registry based on the scheme of store_uri
Args:
store_uri: The store URI. If None, it will be inferred from the environment. This
URI is used to select which tracking store implementation to instantiate
and is passed to the constructor of the imp... | get_store_builder | python | mlflow/mlflow | mlflow/tracking/registry.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/registry.py | Apache-2.0 |
def in_context(self):
"""Determine if MLflow is running in this context.
Returns:
bool indicating if in this context.
""" | Determine if MLflow is running in this context.
Returns:
bool indicating if in this context.
| in_context | python | mlflow/mlflow | mlflow/tracking/context/abstract_context.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/context/abstract_context.py | Apache-2.0 |
def tags(self):
"""Generate context-specific tags.
Returns:
dict of tags.
""" | Generate context-specific tags.
Returns:
dict of tags.
| tags | python | mlflow/mlflow | mlflow/tracking/context/abstract_context.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/context/abstract_context.py | Apache-2.0 |
def resolve_tags(tags=None, ignore: Optional[list[RunContextProvider]] = None):
"""Generate a set of tags for the current run context. Tags are resolved in the order,
contexts are registered. Argument tags are applied last.
This function iterates through all run context providers in the registry. Additiona... | Generate a set of tags for the current run context. Tags are resolved in the order,
contexts are registered. Argument tags are applied last.
This function iterates through all run context providers in the registry. Additional context
providers can be registered as described in
:py:class:`mlflow.trackin... | resolve_tags | python | mlflow/mlflow | mlflow/tracking/context/registry.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/context/registry.py | Apache-2.0 |
def in_context(self):
"""Determine if the MLflow client is running in a context where this provider can
identify an associated MLflow Experiment ID.
Returns:
True if the MLflow client is running in a context where the provider
can identify an associated MLflow Experiment... | Determine if the MLflow client is running in a context where this provider can
identify an associated MLflow Experiment ID.
Returns:
True if the MLflow client is running in a context where the provider
can identify an associated MLflow Experiment ID. False otherwise.
| in_context | python | mlflow/mlflow | mlflow/tracking/default_experiment/abstract_context.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/default_experiment/abstract_context.py | Apache-2.0 |
def get_experiment_id(self):
"""Provide the MLflow Experiment ID for the current MLflow client context.
Assumes that ``in_context()`` is ``True``.
Returns:
The ID of the MLflow Experiment associated with the current context.
""" | Provide the MLflow Experiment ID for the current MLflow client context.
Assumes that ``in_context()`` is ``True``.
Returns:
The ID of the MLflow Experiment associated with the current context.
| get_experiment_id | python | mlflow/mlflow | mlflow/tracking/default_experiment/abstract_context.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/default_experiment/abstract_context.py | Apache-2.0 |
def get_experiment_id() -> Optional[str]:
"""Get an experiment ID for the current context.
The experiment ID is fetched by querying providers, in the order that they were registered.
This function iterates through all default experiment context providers in the registry.
Returns:
An experiment... | Get an experiment ID for the current context.
The experiment ID is fetched by querying providers, in the order that they were registered.
This function iterates through all default experiment context providers in the registry.
Returns:
An experiment_id.
| get_experiment_id | python | mlflow/mlflow | mlflow/tracking/default_experiment/registry.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/default_experiment/registry.py | Apache-2.0 |
def get_name(self):
"""Get the name of the request auth provider.
Returns:
str of request auth provider name.
""" | Get the name of the request auth provider.
Returns:
str of request auth provider name.
| get_name | python | mlflow/mlflow | mlflow/tracking/request_auth/abstract_request_auth_provider.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/request_auth/abstract_request_auth_provider.py | Apache-2.0 |
def get_auth(self):
"""
Generate request auth object (e.g., `requests.auth import HTTPBasicAuth`). See
https://requests.readthedocs.io/en/latest/user/authentication/ for more details.
Returns:
request auth object.
""" |
Generate request auth object (e.g., `requests.auth import HTTPBasicAuth`). See
https://requests.readthedocs.io/en/latest/user/authentication/ for more details.
Returns:
request auth object.
| get_auth | python | mlflow/mlflow | mlflow/tracking/request_auth/abstract_request_auth_provider.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/request_auth/abstract_request_auth_provider.py | Apache-2.0 |
def fetch_auth(request_auth):
"""
Find the request auth from registered providers based on the auth provider's name.
The auth provider's name can be provided through environment variable `MLFLOW_TRACKING_AUTH`.
This function iterates through all request auth providers in the registry. Additional contex... |
Find the request auth from registered providers based on the auth provider's name.
The auth provider's name can be provided through environment variable `MLFLOW_TRACKING_AUTH`.
This function iterates through all request auth providers in the registry. Additional context
providers can be registered as ... | fetch_auth | python | mlflow/mlflow | mlflow/tracking/request_auth/registry.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/request_auth/registry.py | Apache-2.0 |
def request_headers(self):
"""Generate context-specific request headers.
Returns:
dict of request headers.
""" | Generate context-specific request headers.
Returns:
dict of request headers.
| request_headers | python | mlflow/mlflow | mlflow/tracking/request_header/abstract_request_header_provider.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/request_header/abstract_request_header_provider.py | Apache-2.0 |
def resolve_request_headers(request_headers=None):
"""Generate a set of request headers from registered providers.
Request headers are resolved in the order that providers are registered. Argument headers are
applied last. This function iterates through all request header providers in the registry.
Add... | Generate a set of request headers from registered providers.
Request headers are resolved in the order that providers are registered. Argument headers are
applied last. This function iterates through all request header providers in the registry.
Additional context providers can be registered as described i... | resolve_request_headers | python | mlflow/mlflow | mlflow/tracking/request_header/registry.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/request_header/registry.py | Apache-2.0 |
def __init__(self, registry_uri, tracking_uri):
"""
Args:
registry_uri: Address of local or remote model registry server.
tracking_uri: Address of local or remote tracking server.
"""
self.registry_uri = registry_uri
self.tracking_uri = tracking_uri
... |
Args:
registry_uri: Address of local or remote model registry server.
tracking_uri: Address of local or remote tracking server.
| __init__ | python | mlflow/mlflow | mlflow/tracking/_model_registry/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_model_registry/client.py | Apache-2.0 |
def create_registered_model(self, name, tags=None, description=None, deployment_job_id=None):
"""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 ... | 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.
... | create_registered_model | python | mlflow/mlflow | mlflow/tracking/_model_registry/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_model_registry/client.py | Apache-2.0 |
def update_registered_model(self, name, description, deployment_job_id=None):
"""Updates description for RegisteredModel entity.
Backend raises exception if a registered model with given name does not exist.
Args:
name: Name of the registered model to update.
descriptio... | Updates description for RegisteredModel entity.
Backend raises exception if a registered model with given name does not exist.
Args:
name: Name of the registered model to update.
description: New description.
deployment_job_id: Optional deployment job ID.
R... | update_registered_model | python | mlflow/mlflow | mlflow/tracking/_model_registry/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_model_registry/client.py | Apache-2.0 |
def rename_registered_model(self, name, new_name):
"""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.... | 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.
| rename_registered_model | python | mlflow/mlflow | mlflow/tracking/_model_registry/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_model_registry/client.py | Apache-2.0 |
def search_registered_models(
self,
filter_string=None,
max_results=SEARCH_REGISTERED_MODEL_MAX_RESULTS_DEFAULT,
order_by=None,
page_token=None,
):
"""Search for registered models in backend that satisfy the filter criteria.
Args:
filter_string: F... | Search for registered models in backend that satisfy the filter criteria.
Args:
filter_string: Filter query string, defaults to searching all registered models.
max_results: Maximum number of registered models desired.
order_by: List of column names with ASC|DESC annotation,... | search_registered_models | python | mlflow/mlflow | mlflow/tracking/_model_registry/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_model_registry/client.py | Apache-2.0 |
def create_model_version(
self,
name,
source,
run_id=None,
tags=None,
run_link=None,
description=None,
await_creation_for=DEFAULT_AWAIT_MAX_SLEEP_SECONDS,
local_model_path=None,
model_id: Optional[str] = None,
):
"""Create a new... | Create a new model version from given source.
Args:
name: Name of the containing registered model.
source: URI indicating the location of the model artifacts.
run_id: Run ID from MLflow tracking server that generated the model.
tags: A dictionary of key-value pai... | create_model_version | python | mlflow/mlflow | mlflow/tracking/_model_registry/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_model_registry/client.py | Apache-2.0 |
def transition_model_version_stage(self, name, version, stage, archive_existing_versions=False):
"""Update model version stage.
Args:
name: Registered model name.
version: Registered model version.
stage: New desired stage for this model version.
archive_... | 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... | transition_model_version_stage | python | mlflow/mlflow | mlflow/tracking/_model_registry/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_model_registry/client.py | Apache-2.0 |
def search_model_versions(
self,
filter_string=None,
max_results=SEARCH_MODEL_VERSION_MAX_RESULTS_DEFAULT,
order_by=None,
page_token=None,
):
"""Search for model versions in backend that satisfy the filter criteria.
.. warning:
The model version ... | 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: A filter string expression. Currently supports a single filter
condi... | search_model_versions | python | mlflow/mlflow | mlflow/tracking/_model_registry/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_model_registry/client.py | Apache-2.0 |
def create_prompt(
self,
name: str,
description: Optional[str] = None,
tags: Optional[dict[str, str]] = None,
) -> Prompt:
"""
Create a new prompt in the registry.
This method delegates directly to the store, providing full Unity Catalog support
when ... |
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: Op... | create_prompt | python | mlflow/mlflow | mlflow/tracking/_model_registry/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_model_registry/client.py | Apache-2.0 |
def search_prompts(
self,
filter_string: Optional[str] = None,
max_results: Optional[int] = None,
order_by: Optional[list[str]] = None,
page_token: Optional[str] = None,
) -> PagedList[Prompt]:
"""
Search for prompts in the registry.
This method deleg... |
Search for prompts in the registry.
This method delegates directly to the store, providing Unity Catalog support
when used with Unity Catalog registries.
Args:
filter_string: Filter query string. For Unity Catalog registries, must include
catalog and schema... | search_prompts | python | mlflow/mlflow | mlflow/tracking/_model_registry/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_model_registry/client.py | Apache-2.0 |
def create_prompt_version(
self,
name: str,
template: str,
description: Optional[str] = None,
tags: Optional[dict[str, str]] = None,
) -> PromptVersion:
"""
Create a new version of an existing prompt.
This method delegates directly to the store, provi... |
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 text for this version.
... | create_prompt_version | python | mlflow/mlflow | mlflow/tracking/_model_registry/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_model_registry/client.py | Apache-2.0 |
def search_prompt_versions(
self, name: str, max_results: Optional[int] = None, page_token: Optional[str] = None
):
"""
Search prompt versions for a given prompt name.
This method delegates directly to the store. Only supported in Unity Catalog registries.
Args:
... |
Search prompt versions for a given prompt name.
This method delegates directly to the store. Only supported in Unity Catalog registries.
Args:
name: Name of the prompt to search versions for.
max_results: Maximum number of versions to return.
page_token: To... | search_prompt_versions | python | mlflow/mlflow | mlflow/tracking/_model_registry/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_model_registry/client.py | Apache-2.0 |
def link_prompt_versions_to_trace(
self, prompt_versions: list[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 the prompt versions ... |
Link multiple prompt versions to a trace.
Args:
prompt_versions: List of PromptVersion objects to link.
trace_id: Trace ID to link the prompt versions to.
| link_prompt_versions_to_trace | python | mlflow/mlflow | mlflow/tracking/_model_registry/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_model_registry/client.py | Apache-2.0 |
def register_model(
model_uri,
name,
await_registration_for=DEFAULT_AWAIT_MAX_SLEEP_SECONDS,
*,
tags: Optional[dict[str, Any]] = None,
env_pack: Optional[EnvPackType] = None,
) -> ModelVersion:
"""Create a new model version in model registry for the model files specified by ``model_uri``.
... | 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. Use a ``runs:/`` URI if you want to
... | register_model | python | mlflow/mlflow | mlflow/tracking/_model_registry/fluent.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_model_registry/fluent.py | Apache-2.0 |
def _get_logged_models_from_run(source_run: Run, model_name: str) -> list[LoggedModel]:
"""Get all logged models from the source rnu that have the specified model name.
Args:
source_run: Source run from which to retrieve logged models.
model_name: Name of the model to retrieve.
"""
clie... | Get all logged models from the source rnu that have the specified model name.
Args:
source_run: Source run from which to retrieve logged models.
model_name: Name of the model to retrieve.
| _get_logged_models_from_run | python | mlflow/mlflow | mlflow/tracking/_model_registry/fluent.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_model_registry/fluent.py | Apache-2.0 |
def search_registered_models(
max_results: Optional[int] = None,
filter_string: Optional[str] = None,
order_by: Optional[list[str]] = None,
) -> list[RegisteredModel]:
"""Search for registered models that satisfy the filter criteria.
Args:
max_results: If passed, specifies the maximum numbe... | 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'"),
... | search_registered_models | python | mlflow/mlflow | mlflow/tracking/_model_registry/fluent.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_model_registry/fluent.py | Apache-2.0 |
def search_model_versions(
max_results: Optional[int] = None,
filter_string: Optional[str] = None,
order_by: Optional[list[str]] = None,
) -> list[ModelVersion]:
"""Search for model versions that satisfy the filter criteria.
.. warning:
The model version search results may not have aliases... | 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... | search_model_versions | python | mlflow/mlflow | mlflow/tracking/_model_registry/fluent.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_model_registry/fluent.py | Apache-2.0 |
def set_model_version_tag(
name: str,
version: Optional[str] = None,
key: Optional[str] = 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 requir... |
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_model_version_tag | python | mlflow/mlflow | mlflow/tracking/_model_registry/fluent.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_model_registry/fluent.py | Apache-2.0 |
def load_prompt(
name_or_uri: str,
version: Optional[Union[str, int]] = None,
allow_missing: bool = False,
link_to_model: bool = True,
model_id: Optional[str] = None,
) -> PromptVersion:
"""
Load a :py:class:`Prompt <mlflow.entities.Prompt>` from the MLflow Prompt Registry.
The prompt c... |
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 us... | load_prompt | python | mlflow/mlflow | mlflow/tracking/_model_registry/fluent.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_model_registry/fluent.py | Apache-2.0 |
def _load_prompt_cached(
name_or_uri: str,
version: Optional[Union[str, int]] = None,
allow_missing: bool = False,
) -> Optional[PromptVersion]:
"""
Internal cached function to load prompts from registry.
"""
return _load_prompt_not_cached(name_or_uri, version, allow_missing) |
Internal cached function to load prompts from registry.
| _load_prompt_cached | python | mlflow/mlflow | mlflow/tracking/_model_registry/fluent.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_model_registry/fluent.py | Apache-2.0 |
def _load_prompt_not_cached(
name_or_uri: str,
version: Optional[Union[str, int]] = None,
allow_missing: bool = False,
) -> Optional[PromptVersion]:
"""
Load prompt from client, handling URI parsing.
"""
client = MlflowClient()
# Use utility to handle URI vs name+version parsing
par... |
Load prompt from client, handling URI parsing.
| _load_prompt_not_cached | python | mlflow/mlflow | mlflow/tracking/_model_registry/fluent.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_model_registry/fluent.py | Apache-2.0 |
def 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.
E... |
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 ... | set_prompt_alias | python | mlflow/mlflow | mlflow/tracking/_model_registry/fluent.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_model_registry/fluent.py | Apache-2.0 |
def get_store(self, store_uri=None, tracking_uri=None):
"""Get a store from the registry based on the scheme of store_uri
Args:
store_uri: The store URI. If None, it will be inferred from the environment. This URI
is used to select which tracking store implementation to inst... | Get a store from the registry based on the scheme of store_uri
Args:
store_uri: The store URI. If None, it will be inferred from the environment. This URI
is used to select which tracking store implementation to instantiate and
is passed to the constructor of the imp... | get_store | python | mlflow/mlflow | mlflow/tracking/_model_registry/registry.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_model_registry/registry.py | Apache-2.0 |
def _get_store_with_resolved_uri(self, resolved_store_uri, resolved_tracking_uri):
"""
Retrieve the store associated with a resolved (non-None) store URI and an artifact URI.
Caching is done on resolved URIs because the meaning of an unresolved (None) URI may change
depending on external... |
Retrieve the store associated with a resolved (non-None) store URI and an artifact URI.
Caching is done on resolved URIs because the meaning of an unresolved (None) URI may change
depending on external configuration, such as environment variables
| _get_store_with_resolved_uri | python | mlflow/mlflow | mlflow/tracking/_model_registry/registry.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_model_registry/registry.py | Apache-2.0 |
def 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 pro... | 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 ... | set_registry_uri | python | mlflow/mlflow | mlflow/tracking/_model_registry/utils.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_model_registry/utils.py | Apache-2.0 |
def _get_default_registry_uri_for_tracking_uri(tracking_uri: Optional[str]) -> Optional[str]:
"""
Get the default registry URI for a given tracking URI.
If the tracking URI starts with "databricks", returns "databricks-uc" with profile if present.
Otherwise, returns the tracking URI itself.
Args:
... |
Get the default registry URI for a given tracking URI.
If the tracking URI starts with "databricks", returns "databricks-uc" with profile if present.
Otherwise, returns the tracking URI itself.
Args:
tracking_uri: The tracking URI to get the default registry URI for
Returns:
The ... | _get_default_registry_uri_for_tracking_uri | python | mlflow/mlflow | mlflow/tracking/_model_registry/utils.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_model_registry/utils.py | Apache-2.0 |
def _resolve_registry_uri(
registry_uri: Optional[str] = None, tracking_uri: Optional[str] = None
) -> Optional[str]:
"""
Resolve the registry URI following the same logic as get_registry_uri().
"""
return (
registry_uri
or _get_registry_uri_from_context()
or _get_default_reg... |
Resolve the registry URI following the same logic as get_registry_uri().
| _resolve_registry_uri | python | mlflow/mlflow | mlflow/tracking/_model_registry/utils.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_model_registry/utils.py | Apache-2.0 |
def get_metric_history(self, run_id, key):
"""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.Metri... | 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.
| get_metric_history | python | mlflow/mlflow | mlflow/tracking/_tracking_service/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_tracking_service/client.py | Apache-2.0 |
def create_run(self, experiment_id, start_time=None, tags=None, run_name=None):
"""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:fun... | 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... | create_run | python | mlflow/mlflow | mlflow/tracking/_tracking_service/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_tracking_service/client.py | Apache-2.0 |
def create_experiment(self, name, artifact_location=None, tags=None):
"""Create an experiment.
Args:
name: The experiment name. Must be unique.
artifact_location: The location to store run artifacts. If not provided, the server
picks an appropriate default.
... | Create an experiment.
Args:
name: The experiment name. Must be unique.
artifact_location: The location to store run artifacts. If not provided, the server
picks an appropriate default.
tags: A dictionary of key-value pairs that are converted into
... | create_experiment | python | mlflow/mlflow | mlflow/tracking/_tracking_service/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_tracking_service/client.py | Apache-2.0 |
def log_metric(
self,
run_id,
key,
value,
timestamp=None,
step=None,
synchronous=True,
dataset_name: Optional[str] = None,
dataset_digest: Optional[str] = None,
model_id: Optional[str] = None,
) -> Optional[RunOperations]:
"""Lo... | 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
su... | log_metric | python | mlflow/mlflow | mlflow/tracking/_tracking_service/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_tracking_service/client.py | Apache-2.0 |
def log_param(self, run_id, key, value, synchronous=True):
"""Log a parameter (e.g. model hyperparameter) against the run ID. Value is converted to
a string.
Args:
run_id: ID of the run to log the parameter against.
key: Name of the parameter.
value: Value of... | Log a parameter (e.g. model hyperparameter) against the run ID. Value is converted to
a string.
Args:
run_id: ID of the run to log the parameter against.
key: Name of the parameter.
value: Value of the parameter.
synchronous: *Experimental* If True, block... | log_param | python | mlflow/mlflow | mlflow/tracking/_tracking_service/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_tracking_service/client.py | Apache-2.0 |
def set_tag(self, run_id, key, value, synchronous=True) -> Optional[RunOperations]:
"""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
... | 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 s... | set_tag | python | mlflow/mlflow | mlflow/tracking/_tracking_service/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_tracking_service/client.py | Apache-2.0 |
def update_run(self, run_id, status=None, name=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 b... | 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... | update_run | python | mlflow/mlflow | mlflow/tracking/_tracking_service/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_tracking_service/client.py | Apache-2.0 |
def log_batch(
self, run_id, metrics=(), params=(), tags=(), synchronous=True
) -> Optional[RunOperations]:
"""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.
... | 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... | log_batch | python | mlflow/mlflow | mlflow/tracking/_tracking_service/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_tracking_service/client.py | Apache-2.0 |
def log_inputs(
self,
run_id: str,
datasets: Optional[list[DatasetInput]] = None,
models: Optional[list[LoggedModelInput]] = None,
):
"""Log one or more dataset inputs to a run.
Args:
run_id: String ID of the run.
datasets: List of :py:class:`... | 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:
MlflowExcepti... | log_inputs | python | mlflow/mlflow | mlflow/tracking/_tracking_service/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_tracking_service/client.py | Apache-2.0 |
def log_artifact(self, run_id, local_path, artifact_path=None):
"""
Write a local file or directory to the remote ``artifact_uri``.
Args:
run_id: String ID of the run.
local_path: Path to the file or directory to write.
artifact_path: If provided, the directo... |
Write a local file or directory to the remote ``artifact_uri``.
Args:
run_id: String ID of the run.
local_path: Path to the file or directory to write.
artifact_path: If provided, the directory in ``artifact_uri`` to write to.
| log_artifact | python | mlflow/mlflow | mlflow/tracking/_tracking_service/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_tracking_service/client.py | Apache-2.0 |
def _log_artifact_async(self, run_id, filename, artifact_path=None, artifact=None):
"""
Write an artifact to the remote ``artifact_uri`` asynchronously.
Args:
run_id: String ID of the run.
filename: Filename of the artifact to be logged.
artifact_path: If pro... |
Write an artifact to the remote ``artifact_uri`` asynchronously.
Args:
run_id: String ID of the run.
filename: Filename of the artifact to be logged.
artifact_path: If provided, the directory in ``artifact_uri`` to write to.
artifact: The artifact to be ... | _log_artifact_async | python | mlflow/mlflow | mlflow/tracking/_tracking_service/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_tracking_service/client.py | Apache-2.0 |
def list_artifacts(self, run_id, path=None):
"""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 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`
| list_artifacts | python | mlflow/mlflow | mlflow/tracking/_tracking_service/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_tracking_service/client.py | Apache-2.0 |
def list_logged_model_artifacts(
self, model_id: str, path: Optional[str] = None
) -> list[FileInfo]:
"""List the artifacts for a logged model.
Args:
model_id: The model to list artifacts from.
path: The model's relative artifact path to list from. By default it is s... | List the artifacts for a logged model.
Args:
model_id: The model to list artifacts from.
path: The model'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.FileIn... | list_logged_model_artifacts | python | mlflow/mlflow | mlflow/tracking/_tracking_service/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_tracking_service/client.py | Apache-2.0 |
def download_artifacts(self, run_id: str, path: str, dst_path: Optional[str] = None):
"""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... | 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... | download_artifacts | python | mlflow/mlflow | mlflow/tracking/_tracking_service/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_tracking_service/client.py | Apache-2.0 |
def set_terminated(self, run_id, status=None, end_time=None):
"""Set a run's status to terminated.
Args:
run_id: String ID of the run.
status: A string value of :py:class:`mlflow.entities.RunStatus`. Defaults to "FINISHED".
end_time: If not provided, defaults to the ... | Set a run's status to terminated.
Args:
run_id: String ID of the run.
status: A string value of :py:class:`mlflow.entities.RunStatus`. Defaults to "FINISHED".
end_time: If not provided, defaults to the current time.
| set_terminated | python | mlflow/mlflow | mlflow/tracking/_tracking_service/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_tracking_service/client.py | Apache-2.0 |
def search_runs(
self,
experiment_ids,
filter_string="",
run_view_type=ViewType.ACTIVE_ONLY,
max_results=SEARCH_MAX_RESULTS_DEFAULT,
order_by=None,
page_token=None,
):
"""Search experiments that fit the search criteria.
Args:
exper... | Search experiments that fit the search 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
... | search_runs | python | mlflow/mlflow | mlflow/tracking/_tracking_service/client.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_tracking_service/client.py | Apache-2.0 |
def get_store(self, store_uri=None, artifact_uri=None):
"""Get a store from the registry based on the scheme of store_uri
Args:
store_uri: The store URI. If None, it will be inferred from the environment. This URI
is used to select which tracking store implementation to inst... | Get a store from the registry based on the scheme of store_uri
Args:
store_uri: The store URI. If None, it will be inferred from the environment. This URI
is used to select which tracking store implementation to instantiate and
is passed to the constructor of the imp... | get_store | python | mlflow/mlflow | mlflow/tracking/_tracking_service/registry.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_tracking_service/registry.py | Apache-2.0 |
def is_tracking_uri_set():
"""Returns True if the tracking URI has been set, False otherwise."""
if _tracking_uri or MLFLOW_TRACKING_URI.get():
return True
return False | Returns True if the tracking URI has been set, False otherwise. | is_tracking_uri_set | python | mlflow/mlflow | mlflow/tracking/_tracking_service/utils.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_tracking_service/utils.py | Apache-2.0 |
def set_tracking_uri(uri: Union[str, 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
... |
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... | set_tracking_uri | python | mlflow/mlflow | mlflow/tracking/_tracking_service/utils.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_tracking_service/utils.py | Apache-2.0 |
def _use_tracking_uri(uri: str) -> Generator[None, None, None]:
"""Temporarily use the specified tracking URI.
Args:
uri: The tracking URI to use.
"""
old_tracking_uri = _tracking_uri
try:
set_tracking_uri(uri)
yield
finally:
set_tracking_uri(old_tracking_uri) | Temporarily use the specified tracking URI.
Args:
uri: The tracking URI to use.
| _use_tracking_uri | python | mlflow/mlflow | mlflow/tracking/_tracking_service/utils.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_tracking_service/utils.py | Apache-2.0 |
def 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 c... | 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_u... | get_tracking_uri | python | mlflow/mlflow | mlflow/tracking/_tracking_service/utils.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_tracking_service/utils.py | Apache-2.0 |
def _get_git_url_if_present(uri):
"""Return the path git_uri#sub_directory if the URI passed is a local path that's part of
a Git repo, or returns the original URI otherwise.
Args:
uri: The expanded uri.
Returns:
The git_uri#sub_directory if the uri is part of a Git repo, otherwise ret... | Return the path git_uri#sub_directory if the URI passed is a local path that's part of
a Git repo, or returns the original URI otherwise.
Args:
uri: The expanded uri.
Returns:
The git_uri#sub_directory if the uri is part of a Git repo, otherwise return the original
uri.
| _get_git_url_if_present | python | mlflow/mlflow | mlflow/tracking/_tracking_service/utils.py | https://github.com/mlflow/mlflow/blob/master/mlflow/tracking/_tracking_service/utils.py | Apache-2.0 |
def build_flavor_config_from_local_checkpoint(
local_checkpoint_dir: str,
task: str,
processor=None,
torch_dtype=None,
) -> dict[str, Any]:
"""
Generates the flavor metadata from a Hugging Face model repository ID
e.g. "meta-llama/Meta-Llama-3.1-405B, instead of the pipeline instance in-memo... |
Generates the flavor metadata from a Hugging Face model repository ID
e.g. "meta-llama/Meta-Llama-3.1-405B, instead of the pipeline instance in-memory.
| build_flavor_config_from_local_checkpoint | python | mlflow/mlflow | mlflow/transformers/flavor_config.py | https://github.com/mlflow/mlflow/blob/master/mlflow/transformers/flavor_config.py | Apache-2.0 |
def update_flavor_conf_to_persist_pretrained_model(
original_flavor_conf: dict[str, Any],
) -> dict[str, Any]:
"""
Updates the flavor configuration that was saved with save_pretrained=False to the one that
includes the local path to the model binary file.
"""
flavor_conf = original_flavor_conf.c... |
Updates the flavor configuration that was saved with save_pretrained=False to the one that
includes the local path to the model binary file.
| update_flavor_conf_to_persist_pretrained_model | python | mlflow/mlflow | mlflow/transformers/flavor_config.py | https://github.com/mlflow/mlflow/blob/master/mlflow/transformers/flavor_config.py | Apache-2.0 |
def is_valid_hf_repo_id(maybe_repo_id: Optional[str]) -> bool:
"""
Check if the given string is a valid HuggingFace repo identifier e.g. "username/repo_id".
"""
if not maybe_repo_id or os.path.isdir(maybe_repo_id):
return False
try:
from huggingface_hub.utils import HFValidationErr... |
Check if the given string is a valid HuggingFace repo identifier e.g. "username/repo_id".
| is_valid_hf_repo_id | python | mlflow/mlflow | mlflow/transformers/hub_utils.py | https://github.com/mlflow/mlflow/blob/master/mlflow/transformers/hub_utils.py | Apache-2.0 |
def infer_signature_from_llm_inference_task(
inference_task: str, signature: Optional[ModelSignature] = None
) -> ModelSignature:
"""
Infers the signature according to the MLflow inference task.
Raises exception if a signature is given.
"""
inferred_signature = _SIGNATURE_FOR_LLM_INFERENCE_TASK[... |
Infers the signature according to the MLflow inference task.
Raises exception if a signature is given.
| infer_signature_from_llm_inference_task | python | mlflow/mlflow | mlflow/transformers/llm_inference_utils.py | https://github.com/mlflow/mlflow/blob/master/mlflow/transformers/llm_inference_utils.py | Apache-2.0 |
def convert_messages_to_prompt(messages: list[dict], tokenizer) -> str:
"""For the Chat inference task, apply chat template to messages to create prompt.
Args:
messages: List of message e.g. [{"role": user, "content": xxx}, ...]
tokenizer: The tokenizer object used for inference.
Returns:
... | For the Chat inference task, apply chat template to messages to create prompt.
Args:
messages: List of message e.g. [{"role": user, "content": xxx}, ...]
tokenizer: The tokenizer object used for inference.
Returns:
The prompt string contains the messages.
| convert_messages_to_prompt | python | mlflow/mlflow | mlflow/transformers/llm_inference_utils.py | https://github.com/mlflow/mlflow/blob/master/mlflow/transformers/llm_inference_utils.py | Apache-2.0 |
def preprocess_llm_inference_input(
data: Union[pd.DataFrame, dict],
params: Optional[dict[str, Any]] = None,
flavor_config: Optional[dict[str, Any]] = None,
) -> tuple[list[Any], dict[str, Any]]:
"""
When a MLflow inference task is given, return updated `data` and `params` that
- Extract the pa... |
When a MLflow inference task is given, return updated `data` and `params` that
- Extract the parameters from the input data (from the first row if passed multiple rows)
- Replace OpenAI specific parameters with Hugging Face specific parameters, in particular
- `max_tokens` with `max_new_tokens`
... | preprocess_llm_inference_input | python | mlflow/mlflow | mlflow/transformers/llm_inference_utils.py | https://github.com/mlflow/mlflow/blob/master/mlflow/transformers/llm_inference_utils.py | Apache-2.0 |
def _get_stopping_criteria(stop: Optional[Union[str, list[str]]], model_name: Optional[str] = None):
"""Return a list of Hugging Face stopping criteria objects for the given stop sequences."""
from transformers import AutoTokenizer, StoppingCriteria
if stop is None or model_name is None:
return Non... | Return a list of Hugging Face stopping criteria objects for the given stop sequences. | _get_stopping_criteria | python | mlflow/mlflow | mlflow/transformers/llm_inference_utils.py | https://github.com/mlflow/mlflow/blob/master/mlflow/transformers/llm_inference_utils.py | Apache-2.0 |
def postprocess_output_for_llm_inference_task(
data: list[str],
output_tensors: list[list[int]],
pipeline,
flavor_config,
model_config,
inference_task,
):
"""
Wrap output data with usage information according to the MLflow inference task.
Example:
.. code-block:: python
... |
Wrap output data with usage information according to the MLflow inference task.
Example:
.. code-block:: python
data = ["How to learn Python in 3 weeks?"]
output_tensors = [
[
1128,
304,
...,
... | postprocess_output_for_llm_inference_task | python | mlflow/mlflow | mlflow/transformers/llm_inference_utils.py | https://github.com/mlflow/mlflow/blob/master/mlflow/transformers/llm_inference_utils.py | Apache-2.0 |
def _get_output_and_usage_from_tensor(
prompt: str, output_tensor: list[int], pipeline, flavor_config, model_config, inference_task
):
"""
Decode the output tensor and return the output text and usage information as a dictionary
to make the output in OpenAI compatible format.
"""
usage = _get_to... |
Decode the output tensor and return the output text and usage information as a dictionary
to make the output in OpenAI compatible format.
| _get_output_and_usage_from_tensor | python | mlflow/mlflow | mlflow/transformers/llm_inference_utils.py | https://github.com/mlflow/mlflow/blob/master/mlflow/transformers/llm_inference_utils.py | Apache-2.0 |
def _get_completions_text(prompt: str, output_tensor: list[int], pipeline):
"""Decode generated text from output tensor and remove the input prompt."""
generated_text = pipeline.tokenizer.decode(
output_tensor,
skip_special_tokens=True,
clean_up_tokenization_spaces=True,
)
# In ... | Decode generated text from output tensor and remove the input prompt. | _get_completions_text | python | mlflow/mlflow | mlflow/transformers/llm_inference_utils.py | https://github.com/mlflow/mlflow/blob/master/mlflow/transformers/llm_inference_utils.py | Apache-2.0 |
def _get_token_usage(prompt: str, output_tensor: list[int], pipeline, model_config):
"""Return the prompt tokens, completion tokens, and the total tokens as dict."""
inputs = pipeline.tokenizer(
prompt,
return_tensors=pipeline.framework,
max_length=model_config.get("max_length", None),
... | Return the prompt tokens, completion tokens, and the total tokens as dict. | _get_token_usage | python | mlflow/mlflow | mlflow/transformers/llm_inference_utils.py | https://github.com/mlflow/mlflow/blob/master/mlflow/transformers/llm_inference_utils.py | Apache-2.0 |
def _get_finish_reason(total_tokens: int, completion_tokens: int, model_config):
"""Determine the reason that the text generation finished."""
finish_reason = "stop"
if total_tokens > model_config.get(
"max_length", float("inf")
) or completion_tokens == model_config.get("max_new_tokens", float... | Determine the reason that the text generation finished. | _get_finish_reason | python | mlflow/mlflow | mlflow/transformers/llm_inference_utils.py | https://github.com/mlflow/mlflow/blob/master/mlflow/transformers/llm_inference_utils.py | Apache-2.0 |
def _get_default_task_for_llm_inference_task(llm_inference_task: Optional[str]) -> Optional[str]:
"""
Get corresponding original Transformers task for the given LLM inference task.
NB: This assumes there is only one original Transformers task for each LLM inference
task, which might not be true in th... |
Get corresponding original Transformers task for the given LLM inference task.
NB: This assumes there is only one original Transformers task for each LLM inference
task, which might not be true in the future.
| _get_default_task_for_llm_inference_task | python | mlflow/mlflow | mlflow/transformers/llm_inference_utils.py | https://github.com/mlflow/mlflow/blob/master/mlflow/transformers/llm_inference_utils.py | Apache-2.0 |
def preprocess_llm_embedding_params(
data: Union[pd.DataFrame, dict[str, Any]],
) -> tuple[list[str], dict[str, Any]]:
"""
When `llm/v1/embeddings` task is given, extract the input data (with "input" key) and
parameters, and format the input data into the unified format for easier downstream handling.
... |
When `llm/v1/embeddings` task is given, extract the input data (with "input" key) and
parameters, and format the input data into the unified format for easier downstream handling.
The handling is more complicated than other LLM inference tasks because the embedding endpoint
accepts heterogeneous input... | preprocess_llm_embedding_params | python | mlflow/mlflow | mlflow/transformers/llm_inference_utils.py | https://github.com/mlflow/mlflow/blob/master/mlflow/transformers/llm_inference_utils.py | Apache-2.0 |
def postprocess_output_for_llm_v1_embedding_task(
input_prompts: list[str],
output_tensors: list[list[float]],
tokenizer,
):
"""
Wrap output data with usage information.
Examples:
.. code-block:: python
input_prompt = ["hello world and hello mlflow"]
output_embed... |
Wrap output data with usage information.
Examples:
.. code-block:: python
input_prompt = ["hello world and hello mlflow"]
output_embedding = [0.47137904, 0.4669448, ..., 0.69726706]
output_dicts = postprocess_output_for_llm_v1_embedding_task(
input_p... | postprocess_output_for_llm_v1_embedding_task | python | mlflow/mlflow | mlflow/transformers/llm_inference_utils.py | https://github.com/mlflow/mlflow/blob/master/mlflow/transformers/llm_inference_utils.py | Apache-2.0 |
def save_pipeline_pretrained_weights(path, pipeline, flavor_conf, processor=None):
"""
Save the binary artifacts of the pipeline to the specified local path.
Args:
path: The local path to save the pipeline
pipeline: Transformers pipeline instance
flavor_conf: The flavor configuratio... |
Save the binary artifacts of the pipeline to the specified local path.
Args:
path: The local path to save the pipeline
pipeline: Transformers pipeline instance
flavor_conf: The flavor configuration constructed for the pipeline
processor: Optional processor instance to save alon... | save_pipeline_pretrained_weights | python | mlflow/mlflow | mlflow/transformers/model_io.py | https://github.com/mlflow/mlflow/blob/master/mlflow/transformers/model_io.py | Apache-2.0 |
def save_local_checkpoint(path, checkpoint_dir, flavor_conf, processor=None):
"""
Save the local checkpoint of the model and other components to the specified local path.
Args:
path: The local path to save the pipeline
checkpoint_dir: The local path to the checkpoint directory
flavo... |
Save the local checkpoint of the model and other components to the specified local path.
Args:
path: The local path to save the pipeline
checkpoint_dir: The local path to the checkpoint directory
flavor_conf: The flavor configuration constructed for the pipeline
processor: Opti... | save_local_checkpoint | python | mlflow/mlflow | mlflow/transformers/model_io.py | https://github.com/mlflow/mlflow/blob/master/mlflow/transformers/model_io.py | Apache-2.0 |
def load_model_and_components_from_local(path, flavor_conf, accelerate_conf, device=None):
"""
Load the model and components of a Transformer pipeline from the specified local path.
Args:
path: The local path contains MLflow model artifacts
flavor_conf: The flavor configuration
acce... |
Load the model and components of a Transformer pipeline from the specified local path.
Args:
path: The local path contains MLflow model artifacts
flavor_conf: The flavor configuration
accelerate_conf: The configuration for the accelerate library
device: The device to load the m... | load_model_and_components_from_local | python | mlflow/mlflow | mlflow/transformers/model_io.py | https://github.com/mlflow/mlflow/blob/master/mlflow/transformers/model_io.py | Apache-2.0 |
def load_model_and_components_from_huggingface_hub(flavor_conf, accelerate_conf, device=None):
"""
Load the model and components of a Transformer pipeline from HuggingFace Hub.
Args:
flavor_conf: The flavor configuration
accelerate_conf: The configuration for the accelerate library
... |
Load the model and components of a Transformer pipeline from HuggingFace Hub.
Args:
flavor_conf: The flavor configuration
accelerate_conf: The configuration for the accelerate library
device: The device to load the model onto
| load_model_and_components_from_huggingface_hub | python | mlflow/mlflow | mlflow/transformers/model_io.py | https://github.com/mlflow/mlflow/blob/master/mlflow/transformers/model_io.py | Apache-2.0 |
def _load_class_from_transformers_config(model_name_or_path, revision=None):
"""
This method retrieves the Transformers AutoClass from the transformers config.
Using the correct AutoClass allows us to leverage Transformers' model loading
machinery, which is necessary for supporting models using custom c... |
This method retrieves the Transformers AutoClass from the transformers config.
Using the correct AutoClass allows us to leverage Transformers' model loading
machinery, which is necessary for supporting models using custom code.
| _load_class_from_transformers_config | python | mlflow/mlflow | mlflow/transformers/model_io.py | https://github.com/mlflow/mlflow/blob/master/mlflow/transformers/model_io.py | Apache-2.0 |
def _load_model(model_name_or_path, flavor_conf, accelerate_conf, device, revision=None):
"""
Try to load a model with various loading strategies.
1. Try to load the model with accelerate
2. Try to load the model with the specified device
3. Load the model without the device
"""
import... |
Try to load a model with various loading strategies.
1. Try to load the model with accelerate
2. Try to load the model with the specified device
3. Load the model without the device
| _load_model | python | mlflow/mlflow | mlflow/transformers/model_io.py | https://github.com/mlflow/mlflow/blob/master/mlflow/transformers/model_io.py | Apache-2.0 |
def get_peft_base_model(model):
"""Extract the base model from a PEFT model."""
peft_config = model.peft_config.get(model.active_adapter) if model.peft_config else None
# PEFT usually wraps the base model with two additional classes, one is PeftModel class
# and the other is the adaptor specific class,... | Extract the base model from a PEFT model. | get_peft_base_model | python | mlflow/mlflow | mlflow/transformers/peft.py | https://github.com/mlflow/mlflow/blob/master/mlflow/transformers/peft.py | Apache-2.0 |
def get_model_with_peft_adapter(base_model, peft_adapter_path):
"""
Apply the PEFT adapter to the base model to create a PEFT model.
NB: The alternative way to load PEFT adapter is to use load_adapter API like
`base_model.load_adapter(peft_adapter_path)`, as it injects the adapter weights
into the ... |
Apply the PEFT adapter to the base model to create a PEFT model.
NB: The alternative way to load PEFT adapter is to use load_adapter API like
`base_model.load_adapter(peft_adapter_path)`, as it injects the adapter weights
into the model in-place hence reducing the memory footprint. However, doing so
... | get_model_with_peft_adapter | python | mlflow/mlflow | mlflow/transformers/peft.py | https://github.com/mlflow/mlflow/blob/master/mlflow/transformers/peft.py | Apache-2.0 |
def infer_or_get_default_signature(
pipeline, example=None, model_config=None, flavor_config=None
) -> ModelSignature:
"""
Assigns a default ModelSignature for a given Pipeline type that has pyfunc support. These
default signatures should only be generated and assigned when saving a model iff the user
... |
Assigns a default ModelSignature for a given Pipeline type that has pyfunc support. These
default signatures should only be generated and assigned when saving a model iff the user
has not supplied a signature.
For signature inference in some Pipelines that support complex input types, an input example
... | infer_or_get_default_signature | python | mlflow/mlflow | mlflow/transformers/signature.py | https://github.com/mlflow/mlflow/blob/master/mlflow/transformers/signature.py | Apache-2.0 |
def format_input_example_for_special_cases(input_example, pipeline):
"""
Handles special formatting for specific types of Pipelines so that the displayed example
reflects the correct example input structure that mirrors the behavior of the input parsing
for pyfunc.
"""
input_data = input_example... |
Handles special formatting for specific types of Pipelines so that the displayed example
reflects the correct example input structure that mirrors the behavior of the input parsing
for pyfunc.
| format_input_example_for_special_cases | python | mlflow/mlflow | mlflow/transformers/signature.py | https://github.com/mlflow/mlflow/blob/master/mlflow/transformers/signature.py | Apache-2.0 |
def _extract_torch_dtype_if_set(pipeline) -> Optional[torch.dtype]:
"""
Extract the torch datatype argument if set and return as a string encoded value.
"""
try:
import torch
except ImportError:
# If torch is not installed, safe to assume the model doesn't have a custom torch_dtype
... |
Extract the torch datatype argument if set and return as a string encoded value.
| _extract_torch_dtype_if_set | python | mlflow/mlflow | mlflow/transformers/torch_utils.py | https://github.com/mlflow/mlflow/blob/master/mlflow/transformers/torch_utils.py | Apache-2.0 |
def _deserialize_torch_dtype(dtype_str: str) -> torch.dtype:
"""
Convert the string-encoded `torch_dtype` pipeline argument back to the correct `torch.dtype`
instance value for applying to a loaded pipeline instance.
"""
try:
import torch
except ImportError as e:
raise MlflowExce... |
Convert the string-encoded `torch_dtype` pipeline argument back to the correct `torch.dtype`
instance value for applying to a loaded pipeline instance.
| _deserialize_torch_dtype | python | mlflow/mlflow | mlflow/transformers/torch_utils.py | https://github.com/mlflow/mlflow/blob/master/mlflow/transformers/torch_utils.py | Apache-2.0 |
def 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.
R... |
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... | get_default_pip_requirements | python | mlflow/mlflow | mlflow/transformers/__init__.py | https://github.com/mlflow/mlflow/blob/master/mlflow/transformers/__init__.py | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.