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_traces(): """ A request handler for `GET /mlflow/traces` to search for TraceInfo records in tracking store. """ request_message = _get_request_message( SearchTraces(), schema={ "experiment_ids": [ _assert_array, _assert_item_type_st...
A request handler for `GET /mlflow/traces` to search for TraceInfo records in tracking store.
_search_traces
python
mlflow/mlflow
mlflow/server/handlers.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/handlers.py
Apache-2.0
def _delete_traces(): """ A request handler for `POST /mlflow/traces/delete-traces` to delete TraceInfo records from tracking store. """ request_message = _get_request_message( DeleteTraces(), schema={ "experiment_id": [_assert_string, _assert_required], "max_...
A request handler for `POST /mlflow/traces/delete-traces` to delete TraceInfo records from tracking store.
_delete_traces
python
mlflow/mlflow
mlflow/server/handlers.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/handlers.py
Apache-2.0
def _set_trace_tag(request_id): """ A request handler for `PATCH /mlflow/traces/{request_id}/tags` to set tags on a TraceInfo record """ request_message = _get_request_message( SetTraceTag(), schema={ "key": [_assert_string, _assert_required], "value": [_assert_st...
A request handler for `PATCH /mlflow/traces/{request_id}/tags` to set tags on a TraceInfo record
_set_trace_tag
python
mlflow/mlflow
mlflow/server/handlers.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/handlers.py
Apache-2.0
def _delete_trace_tag(request_id): """ A request handler for `DELETE /mlflow/traces/{request_id}/tags` to delete tags from a TraceInfo record. """ request_message = _get_request_message( DeleteTraceTag(), schema={ "key": [_assert_string, _assert_required], }, ...
A request handler for `DELETE /mlflow/traces/{request_id}/tags` to delete tags from a TraceInfo record.
_delete_trace_tag
python
mlflow/mlflow
mlflow/server/handlers.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/handlers.py
Apache-2.0
def _get_paths(base_path): """ A service endpoints base path is typically something like /mlflow/experiment. We should register paths like /api/2.0/mlflow/experiment and /ajax-api/2.0/mlflow/experiment in the Flask router. """ base_path = _convert_path_parameter_to_flask_format(base_path) re...
A service endpoints base path is typically something like /mlflow/experiment. We should register paths like /api/2.0/mlflow/experiment and /ajax-api/2.0/mlflow/experiment in the Flask router.
_get_paths
python
mlflow/mlflow
mlflow/server/handlers.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/handlers.py
Apache-2.0
def get_endpoints(get_handler=get_handler): """ Returns: List of tuples (path, handler, methods) """ return ( get_service_endpoints(MlflowService, get_handler) + get_service_endpoints(ModelRegistryService, get_handler) + get_service_endpoints(MlflowArtifactsService, get_h...
Returns: List of tuples (path, handler, methods)
get_endpoints
python
mlflow/mlflow
mlflow/server/handlers.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/handlers.py
Apache-2.0
def _validate_content_type(flask_request, allowed_content_types: list[str]): """ Validates that the request content type is one of the allowed content types. Args: flask_request: Flask request object (flask.request) allowed_content_types: A list of allowed content types """ if flask...
Validates that the request content type is one of the allowed content types. Args: flask_request: Flask request object (flask.request) allowed_content_types: A list of allowed content types
_validate_content_type
python
mlflow/mlflow
mlflow/server/validation.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/validation.py
Apache-2.0
def _is_factory(app: str) -> bool: """ Returns True if the given app is a factory function, False otherwise. Args: app: The app to check, e.g. "mlflow.server.app:app """ module, obj_name = app.rsplit(":", 1) mod = importlib.import_module(module) obj = getattr(mod, obj_name) retu...
Returns True if the given app is a factory function, False otherwise. Args: app: The app to check, e.g. "mlflow.server.app:app
_is_factory
python
mlflow/mlflow
mlflow/server/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/__init__.py
Apache-2.0
def get_app_client(app_name: str, *args, **kwargs): """ Instantiate a client provided by an app. Args: app_name: The app name defined in `setup.py`, e.g., "basic-auth". args: Additional arguments passed to the app client constructor. kwargs: Additional keyword arguments passed to th...
Instantiate a client provided by an app. Args: app_name: The app name defined in `setup.py`, e.g., "basic-auth". args: Additional arguments passed to the app client constructor. kwargs: Additional keyword arguments passed to the app client constructor. Returns: An app clie...
get_app_client
python
mlflow/mlflow
mlflow/server/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/__init__.py
Apache-2.0
def _run_server( # noqa: D417 file_store_path, registry_store_uri, default_artifact_root, serve_artifacts, artifacts_only, artifacts_destination, host, port, static_prefix=None, workers=None, gunicorn_opts=None, waitress_opts=None, expose_prometheus=None, app_nam...
Run the MLflow server, wrapping it in gunicorn or waitress on windows Args: static_prefix: If set, the index.html asset will be served from the path static_prefix. If left None, the index.html asset will be served from the root path. Returns: None
_run_server
python
mlflow/mlflow
mlflow/server/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/__init__.py
Apache-2.0
def create_user(self, username: str, password: str): """ Create a new user. Args: username: The username. password: The user's password. Must not be empty string. Raises: mlflow.exceptions.RestException: if the username is already taken. Ret...
Create a new user. Args: username: The username. password: The user's password. Must not be empty string. Raises: mlflow.exceptions.RestException: if the username is already taken. Returns: A single :py:class:`mlflow.server.auth.entitie...
create_user
python
mlflow/mlflow
mlflow/server/auth/client.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/auth/client.py
Apache-2.0
def get_user(self, username: str): """ Get a user with a specific username. Args: username: The username. Raises: mlflow.exceptions.RestException: if the user does not exist Returns: A single :py:class:`mlflow.server.auth.entities.User` obje...
Get a user with a specific username. Args: username: The username. Raises: mlflow.exceptions.RestException: if the user does not exist Returns: A single :py:class:`mlflow.server.auth.entities.User` object. .. code-block:: bash ...
get_user
python
mlflow/mlflow
mlflow/server/auth/client.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/auth/client.py
Apache-2.0
def update_user_password(self, username: str, password: str): """ Update the password of a specific user. Args: username: The username. password: The new password. Raises: mlflow.exceptions.RestException: if the user does not exist .. code-b...
Update the password of a specific user. Args: username: The username. password: The new password. Raises: mlflow.exceptions.RestException: if the user does not exist .. code-block:: bash :caption: Example export MLFLOW_TRAC...
update_user_password
python
mlflow/mlflow
mlflow/server/auth/client.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/auth/client.py
Apache-2.0
def update_user_admin(self, username: str, is_admin: bool): """ Update the admin status of a specific user. Args: username: The username. is_admin: The new admin status. Raises: mlflow.exceptions.RestException: if the user does not exist .. ...
Update the admin status of a specific user. Args: username: The username. is_admin: The new admin status. Raises: mlflow.exceptions.RestException: if the user does not exist .. code-block:: bash :caption: Example export MLF...
update_user_admin
python
mlflow/mlflow
mlflow/server/auth/client.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/auth/client.py
Apache-2.0
def delete_user(self, username: str): """ Delete a specific user. Args: username: The username. Raises: mlflow.exceptions.RestException: if the user does not exist .. code-block:: bash :caption: Example export MLFLOW_TRACKING_US...
Delete a specific user. Args: username: The username. Raises: mlflow.exceptions.RestException: if the user does not exist .. code-block:: bash :caption: Example export MLFLOW_TRACKING_USERNAME=admin export MLFLOW_TRACKING_P...
delete_user
python
mlflow/mlflow
mlflow/server/auth/client.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/auth/client.py
Apache-2.0
def create_experiment_permission(self, experiment_id: str, username: str, permission: str): """ Create a permission on an experiment for a user. Args: experiment_id: The id of the experiment. username: The username. permission: Permission to grant. Must be on...
Create a permission on an experiment for a user. Args: experiment_id: The id of the experiment. username: The username. permission: Permission to grant. Must be one of "READ", "EDIT", "MANAGE" and "NO_PERMISSIONS". Raises: mlflow...
create_experiment_permission
python
mlflow/mlflow
mlflow/server/auth/client.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/auth/client.py
Apache-2.0
def get_experiment_permission(self, experiment_id: str, username: str): """ Get an experiment permission for a user. Args: experiment_id: The id of the experiment. username: The username. Raises: mlflow.exceptions.RestException: if the user does not ...
Get an experiment permission for a user. Args: experiment_id: The id of the experiment. username: The username. Raises: mlflow.exceptions.RestException: if the user does not exist, or no permission exists for this experiment user pair. ...
get_experiment_permission
python
mlflow/mlflow
mlflow/server/auth/client.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/auth/client.py
Apache-2.0
def update_experiment_permission(self, experiment_id: str, username: str, permission: str): """ Update an existing experiment permission for a user. Args: experiment_id: The id of the experiment. username: The username. permission: New permission to grant. Mu...
Update an existing experiment permission for a user. Args: experiment_id: The id of the experiment. username: The username. permission: New permission to grant. Must be one of "READ", "EDIT", "MANAGE" and "NO_PERMISSIONS". Raises: ...
update_experiment_permission
python
mlflow/mlflow
mlflow/server/auth/client.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/auth/client.py
Apache-2.0
def delete_experiment_permission(self, experiment_id: str, username: str): """ Delete an existing experiment permission for a user. Args: experiment_id: The id of the experiment. username: The username. Raises: mlflow.exceptions.RestException: if the...
Delete an existing experiment permission for a user. Args: experiment_id: The id of the experiment. username: The username. Raises: mlflow.exceptions.RestException: if the user does not exist, or no permission exists for this experiment user...
delete_experiment_permission
python
mlflow/mlflow
mlflow/server/auth/client.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/auth/client.py
Apache-2.0
def create_registered_model_permission(self, name: str, username: str, permission: str): """ Create a permission on an registered model for a user. Args: name: The name of the registered model. username: The username. permission: Permission to grant. Must be ...
Create a permission on an registered model for a user. Args: name: The name of the registered model. username: The username. permission: Permission to grant. Must be one of "READ", "EDIT", "MANAGE" and "NO_PERMISSIONS". Raises: m...
create_registered_model_permission
python
mlflow/mlflow
mlflow/server/auth/client.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/auth/client.py
Apache-2.0
def get_registered_model_permission(self, name: str, username: str): """ Get an registered model permission for a user. Args: name: The name of the registered model. username: The username. Raises: mlflow.exceptions.RestException: if the user does no...
Get an registered model permission for a user. Args: name: The name of the registered model. username: The username. Raises: mlflow.exceptions.RestException: if the user does not exist, or no permission exists for this registered model user ...
get_registered_model_permission
python
mlflow/mlflow
mlflow/server/auth/client.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/auth/client.py
Apache-2.0
def update_registered_model_permission(self, name: str, username: str, permission: str): """ Update an existing registered model permission for a user. Args: name: The name of the registered model. username: The username. permission: New permission to grant. ...
Update an existing registered model permission for a user. Args: name: The name of the registered model. username: The username. permission: New permission to grant. Must be one of "READ", "EDIT", "MANAGE" and "NO_PERMISSIONS". Raises: ...
update_registered_model_permission
python
mlflow/mlflow
mlflow/server/auth/client.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/auth/client.py
Apache-2.0
def delete_registered_model_permission(self, name: str, username: str): """ Delete an existing registered model permission for a user. Args: name: The name of the registered model. username: The username. Raises: mlflow.exceptions.RestException: if t...
Delete an existing registered model permission for a user. Args: name: The name of the registered model. username: The username. Raises: mlflow.exceptions.RestException: if the user does not exist, or no permission exists for this registered...
delete_registered_model_permission
python
mlflow/mlflow
mlflow/server/auth/client.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/auth/client.py
Apache-2.0
def _get_permission_from_store_or_default(store_permission_func: Callable[[], str]) -> Permission: """ Attempts to get permission from store, and returns default permission if no record is found. """ try: perm = store_permission_func() except MlflowException as e: if e.error_code...
Attempts to get permission from store, and returns default permission if no record is found.
_get_permission_from_store_or_default
python
mlflow/mlflow
mlflow/server/auth/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/auth/__init__.py
Apache-2.0
def username_is_sender(): """Validate if the request username is the sender""" username = _get_request_param("username") sender = authenticate_request().username return username == sender
Validate if the request username is the sender
username_is_sender
python
mlflow/mlflow
mlflow/server/auth/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/auth/__init__.py
Apache-2.0
def get_auth_func(authorization_function: str) -> Callable[[], Union[Authorization, Response]]: """ Import and return the specified authorization function. Args: authorization_function: A string of the form "module.submodule:auth_func" """ mod_name, fn_name = authorization_function.split(":...
Import and return the specified authorization function. Args: authorization_function: A string of the form "module.submodule:auth_func"
get_auth_func
python
mlflow/mlflow
mlflow/server/auth/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/auth/__init__.py
Apache-2.0
def authenticate_request_basic_auth() -> Union[Authorization, Response]: """Authenticate the request using basic auth.""" if request.authorization is None: return make_basic_auth_response() username = request.authorization.username password = request.authorization.password if store.authenti...
Authenticate the request using basic auth.
authenticate_request_basic_auth
python
mlflow/mlflow
mlflow/server/auth/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/auth/__init__.py
Apache-2.0
def _find_validator(req: Request) -> Optional[Callable[[], bool]]: """ Finds the validator matching the request path and method. """ if "/mlflow/logged-models" in req.path: # logged model routes are not registered in the app # so we need to check them manually return next( ...
Finds the validator matching the request path and method.
_find_validator
python
mlflow/mlflow
mlflow/server/auth/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/auth/__init__.py
Apache-2.0
def delete_can_manage_registered_model_permission(resp: Response): """ Delete registered model permission when the model is deleted. We need to do this because the primary key of the registered model is the name, unlike the experiment where the primary key is experiment_id (UUID). Therefore, we hav...
Delete registered model permission when the model is deleted. We need to do this because the primary key of the registered model is the name, unlike the experiment where the primary key is experiment_id (UUID). Therefore, we have to delete the permission record when the model is deleted otherwise it ...
delete_can_manage_registered_model_permission
python
mlflow/mlflow
mlflow/server/auth/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/auth/__init__.py
Apache-2.0
def filter_search_logged_models(resp: Response) -> None: """ Filter out unreadable logged models from the search results. """ from mlflow.utils.search_utils import SearchLoggedModelsPaginationToken as Token if sender_is_admin(): return response_proto = SearchLoggedModels.Response() ...
Filter out unreadable logged models from the search results.
filter_search_logged_models
python
mlflow/mlflow
mlflow/server/auth/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/auth/__init__.py
Apache-2.0
def rename_registered_model_permission(resp: Response): """ A model registry can be assigned to multiple users with different permissions. Changing the model registry name must be propagated to all users. """ # get registry model name before update data = request.get_json(force=True, silent=Tru...
A model registry can be assigned to multiple users with different permissions. Changing the model registry name must be propagated to all users.
rename_registered_model_permission
python
mlflow/mlflow
mlflow/server/auth/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/auth/__init__.py
Apache-2.0
def create_app(app: Flask = app): """ A factory to enable authentication and authorization for the MLflow server. Args: app: The Flask app to enable authentication and authorization for. Returns: The app with authentication and authorization enabled. """ _logger.warning( ...
A factory to enable authentication and authorization for the MLflow server. Args: app: The Flask app to enable authentication and authorization for. Returns: The app with authentication and authorization enabled.
create_app
python
mlflow/mlflow
mlflow/server/auth/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/auth/__init__.py
Apache-2.0
def get_underlying_model_flavor(model): """ Find the underlying models flavor. Args: model: underlying model of the explainer. """ # checking if underlying model is wrapped if hasattr(model, "inner_model"): unwrapped_model = model.inner_model # check if passed model i...
Find the underlying models flavor. Args: model: underlying model of the explainer.
get_underlying_model_flavor
python
mlflow/mlflow
mlflow/shap/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/shap/__init__.py
Apache-2.0
def _log_artifact_contextmanager(out_file, artifact_path=None): """ A context manager to make it easier to log an artifact. """ with tempfile.TemporaryDirectory() as tmp_dir: tmp_path = os.path.join(tmp_dir, out_file) yield tmp_path mlflow.log_artifact(tmp_path, artifact_path)
A context manager to make it easier to log an artifact.
_log_artifact_contextmanager
python
mlflow/mlflow
mlflow/shap/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/shap/__init__.py
Apache-2.0
def _get_conda_and_pip_dependencies(conda_env): """ Extract conda and pip dependencies from conda environments Args: conda_env: Conda environment """ conda_deps = [] # NB: Set operations are required in case there are multiple references of MLflow as a # dependency to ensure that d...
Extract conda and pip dependencies from conda environments Args: conda_env: Conda environment
_get_conda_and_pip_dependencies
python
mlflow/mlflow
mlflow/shap/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/shap/__init__.py
Apache-2.0
def _merge_environments(shap_environment, model_environment): """ Merge conda environments of underlying model and shap. Args: shap_environment: SHAP conda environment. model_environment: Underlying model conda environment. """ # merge the channels from the two environments and remo...
Merge conda environments of underlying model and shap. Args: shap_environment: SHAP conda environment. model_environment: Underlying model conda environment.
_merge_environments
python
mlflow/mlflow
mlflow/shap/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/shap/__init__.py
Apache-2.0
def load_explainer(model_uri): """ Load a SHAP explainer 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...
Load a SHAP explainer 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...
load_explainer
python
mlflow/mlflow
mlflow/shap/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/shap/__init__.py
Apache-2.0
def _load_explainer(explainer_file, model=None): """ Load a SHAP explainer saved as an MLflow artifact on the local file system. Args: explainer_file: Local filesystem path to the MLflow Model saved with the ``shap`` flavor. model: Model to override underlying explainer model. """ ...
Load a SHAP explainer saved as an MLflow artifact on the local file system. Args: explainer_file: Local filesystem path to the MLflow Model saved with the ``shap`` flavor. model: Model to override underlying explainer model.
_load_explainer
python
mlflow/mlflow
mlflow/shap/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/shap/__init__.py
Apache-2.0
def _get_estimator_info_tags(estimator): """ Returns: A dictionary of MLflow run tag keys and values describing the specified estimator. """ return { "estimator_name": estimator.__class__.__name__, "estimator_class": (estimator.__class__.__module__ + "." + estimator.__class__.__n...
Returns: A dictionary of MLflow run tag keys and values describing the specified estimator.
_get_estimator_info_tags
python
mlflow/mlflow
mlflow/sklearn/utils.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/utils.py
Apache-2.0
def _get_X_y_and_sample_weight(fit_func, fit_args, fit_kwargs): """ Get a tuple of (X, y, sample_weight) in the following steps. 1. Extract X and y from fit_args and fit_kwargs. 2. If the sample_weight argument exists in fit_func, extract it from fit_args or fit_kwargs and return (X, y, sample_w...
Get a tuple of (X, y, sample_weight) in the following steps. 1. Extract X and y from fit_args and fit_kwargs. 2. If the sample_weight argument exists in fit_func, extract it from fit_args or fit_kwargs and return (X, y, sample_weight), otherwise return (X, y) Args: fit_func: A f...
_get_X_y_and_sample_weight
python
mlflow/mlflow
mlflow/sklearn/utils.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/utils.py
Apache-2.0
def _get_classifier_metrics(fitted_estimator, prefix, X, y_true, sample_weight, pos_label): # noqa: D417 """ Compute and record various common metrics for classifiers For (1) precision score: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_score.html (2) recall score: ...
Compute and record various common metrics for classifiers For (1) precision score: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_score.html (2) recall score: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.recall_score.html (3) f1_score: http...
_get_classifier_metrics
python
mlflow/mlflow
mlflow/sklearn/utils.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/utils.py
Apache-2.0
def _get_classifier_artifacts(fitted_estimator, prefix, X, y_true, sample_weight): # noqa: D417 """ Draw and record various common artifacts for classifier For all classifiers, we always log: (1) confusion matrix: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.plot_confusion_mat...
Draw and record various common artifacts for classifier For all classifiers, we always log: (1) confusion matrix: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.plot_confusion_matrix.html For only binary classifiers, we will log: (2) precision recall curve: https://scik...
_get_classifier_artifacts
python
mlflow/mlflow
mlflow/sklearn/utils.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/utils.py
Apache-2.0
def _get_regressor_metrics(fitted_estimator, prefix, X, y_true, sample_weight): # noqa: D417 """ Compute and record various common metrics for regressors For (1) (root) mean squared error: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_squared_error.html (2) mean absolute e...
Compute and record various common metrics for regressors For (1) (root) mean squared error: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_squared_error.html (2) mean absolute error: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_absolute_error.html ...
_get_regressor_metrics
python
mlflow/mlflow
mlflow/sklearn/utils.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/utils.py
Apache-2.0
def _get_meta_estimators_for_autologging(): """ Returns: A list of meta estimator class definitions (e.g., `sklearn.model_selection.GridSearchCV`) that should be included when patching training functions for autologging """ from sklearn.model_selection import GridSearchCV, Random...
Returns: A list of meta estimator class definitions (e.g., `sklearn.model_selection.GridSearchCV`) that should be included when patching training functions for autologging
_get_meta_estimators_for_autologging
python
mlflow/mlflow
mlflow/sklearn/utils.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/utils.py
Apache-2.0
def _is_parameter_search_estimator(estimator): """ Returns: `True` if the specified scikit-learn estimator is a parameter search estimator, such as `GridSearchCV`. `False` otherwise. """ from sklearn.model_selection import GridSearchCV, RandomizedSearchCV parameter_search_estimators...
Returns: `True` if the specified scikit-learn estimator is a parameter search estimator, such as `GridSearchCV`. `False` otherwise.
_is_parameter_search_estimator
python
mlflow/mlflow
mlflow/sklearn/utils.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/utils.py
Apache-2.0
def _log_parameter_search_results_as_artifact(cv_results_df, run_id): """ Records a collection of parameter search results as an MLflow artifact for the specified run. Args: cv_results_df: A Pandas DataFrame containing the results of a parameter search training session, which may be...
Records a collection of parameter search results as an MLflow artifact for the specified run. Args: cv_results_df: A Pandas DataFrame containing the results of a parameter search training session, which may be obtained by parsing the `cv_results_` attribute of a trained par...
_log_parameter_search_results_as_artifact
python
mlflow/mlflow
mlflow/sklearn/utils.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/utils.py
Apache-2.0
def _create_child_runs_for_parameter_search( # noqa: D417 autologging_client, cv_estimator, parent_run, max_tuning_runs, child_tags=None, dataset=None, best_estimator_params=None, best_estimator_model_id=None, ): """ Creates a collection of child runs for a parameter search trai...
Creates a collection of child runs for a parameter search training session. Runs are reconstructed from the `cv_results_` attribute of the specified trained parameter search estimator - `cv_estimator`, which provides relevant performance metrics for each point in the parameter search space. One child r...
_create_child_runs_for_parameter_search
python
mlflow/mlflow
mlflow/sklearn/utils.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/utils.py
Apache-2.0
def save_model( sk_model, path, conda_env=None, code_paths=None, mlflow_model=None, serialization_format=SERIALIZATION_FORMAT_CLOUDPICKLE, signature: ModelSignature = None, input_example: ModelInputExample = None, pip_requirements=None, extra_pip_requirements=None, pyfunc_pre...
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 requi...
save_model
python
mlflow/mlflow
mlflow/sklearn/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/__init__.py
Apache-2.0
def log_model( sk_model, artifact_path: Optional[str] = None, conda_env=None, code_paths=None, serialization_format=SERIALIZATION_FORMAT_CLOUDPICKLE, registered_model_name=None, signature: ModelSignature = None, input_example: ModelInputExample = None, await_registration_for=DEFAULT_...
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()` i...
log_model
python
mlflow/mlflow
mlflow/sklearn/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/__init__.py
Apache-2.0
def _load_model_from_local_file(path, serialization_format): """Load a scikit-learn model saved as an MLflow artifact on the local file system. Args: path: Local filesystem path to the MLflow Model saved with the ``sklearn`` flavor serialization_format: The format in which the model was seriali...
Load a scikit-learn model saved as an MLflow artifact on the local file system. Args: path: Local filesystem path to the MLflow Model saved with the ``sklearn`` flavor serialization_format: The format in which the model was serialized. This should be one of the following: ``mlflow.sklea...
_load_model_from_local_file
python
mlflow/mlflow
mlflow/sklearn/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/__init__.py
Apache-2.0
def _load_pyfunc(path): """ Load PyFunc implementation. Called by ``pyfunc.load_model``. Args: path: Local filesystem path to the MLflow Model with the ``sklearn`` flavor. """ if os.path.isfile(path): # Scikit-learn models saved in older versions of MLflow (<= 1.9.1) specify the ``d...
Load PyFunc implementation. Called by ``pyfunc.load_model``. Args: path: Local filesystem path to the MLflow Model with the ``sklearn`` flavor.
_load_pyfunc
python
mlflow/mlflow
mlflow/sklearn/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/__init__.py
Apache-2.0
def __init__(self, sk_model, original_exception): """ Args: sk_model: The custom sklearn model to be pickled original_exception: The original exception raised """ super().__init__( f"Pickling custom sklearn model {sk_model.__class__.__name__} failed " ...
Args: sk_model: The custom sklearn model to be pickled original_exception: The original exception raised
__init__
python
mlflow/mlflow
mlflow/sklearn/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/__init__.py
Apache-2.0
def _save_model(sk_model, output_path, serialization_format): """ Args: sk_model: The scikit-learn model to serialize. output_path: The file path to which to write the serialized model. serialization_format: The format in which to serialize the model. This should be one of th...
Args: sk_model: The scikit-learn model to serialize. output_path: The file path to which to write the serialized model. serialization_format: The format in which to serialize the model. This should be one of the following: ``mlflow.sklearn.SERIALIZATION_FORMAT_PICKLE`` or ...
_save_model
python
mlflow/mlflow
mlflow/sklearn/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/__init__.py
Apache-2.0
def 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...
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:/<ml...
load_model
python
mlflow/mlflow
mlflow/sklearn/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/__init__.py
Apache-2.0
def is_metric_value_loggable(metric_value): """ Check whether the specified `metric_value` is a numeric value which can be logged as an MLflow metric. """ return isinstance(metric_value, (int, float, np.number)) and not isinstance( metric_value, bool )
Check whether the specified `metric_value` is a numeric value which can be logged as an MLflow metric.
is_metric_value_loggable
python
mlflow/mlflow
mlflow/sklearn/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/__init__.py
Apache-2.0
def register_prediction_result(self, run_id, eval_dataset_name, predict_result, model_id=None): """ Register the relationship id(prediction_result) --> (eval_dataset_name, run_id, model_id) into map `_pred_result_id_mapping` """ value = (eval_dataset_name, run_id, model_...
Register the relationship id(prediction_result) --> (eval_dataset_name, run_id, model_id) into map `_pred_result_id_mapping`
register_prediction_result
python
mlflow/mlflow
mlflow/sklearn/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/__init__.py
Apache-2.0
def gen_metric_call_command(self_obj, metric_fn, *call_pos_args, **call_kwargs): """ Generate metric function call command string like `metric_fn(arg1, arg2, ...)` Note: this method include inspecting argument variable name. So should be called directly from the "patched method", to ens...
Generate metric function call command string like `metric_fn(arg1, arg2, ...)` Note: this method include inspecting argument variable name. So should be called directly from the "patched method", to ensure it capture correct argument variable name. Args: self_obj:...
gen_metric_call_command
python
mlflow/mlflow
mlflow/sklearn/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/__init__.py
Apache-2.0
def register_metric_api_call(self, run_id, metric_name, dataset_name, call_command): """ This method will do: (1) Generate and return metric key, format is: {metric_name}[-{call_index}]_{eval_dataset_name} metric_name is generated by metric function name, if multiple calls on...
This method will do: (1) Generate and return metric key, format is: {metric_name}[-{call_index}]_{eval_dataset_name} metric_name is generated by metric function name, if multiple calls on the same metric API happen, the following calls will be assigned with an increasing "...
register_metric_api_call
python
mlflow/mlflow
mlflow/sklearn/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/__init__.py
Apache-2.0
def get_info_for_metric_api_call(self, call_pos_args, call_kwargs): """ Given a metric api call (include the called metric function, and call arguments) Register the call information (arguments dict) into the `metric_api_call_arg_dict_list_map` and return a tuple of (run_id, eval_dataset...
Given a metric api call (include the called metric function, and call arguments) Register the call information (arguments dict) into the `metric_api_call_arg_dict_list_map` and return a tuple of (run_id, eval_dataset_name, model_id)
get_info_for_metric_api_call
python
mlflow/mlflow
mlflow/sklearn/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/__init__.py
Apache-2.0
def log_post_training_metric(self, run_id, key, value, model_id=None): """ Log the metric into the specified mlflow run. and it will also update the metric_info artifact if needed. If model_id is not None, metrics are logged into the model as well. """ # Note: if the case...
Log the metric into the specified mlflow run. and it will also update the metric_info artifact if needed. If model_id is not None, metrics are logged into the model as well.
log_post_training_metric
python
mlflow/mlflow
mlflow/sklearn/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/__init__.py
Apache-2.0
def _get_metric_name_list(): """ Return metric function name list in `sklearn.metrics` module """ from sklearn import metrics metric_list = [] for metric_method_name in metrics.__all__: # excludes plot_* methods # exclude class (e.g. metrics.ConfusionMatrixDisplay) metri...
Return metric function name list in `sklearn.metrics` module
_get_metric_name_list
python
mlflow/mlflow
mlflow/sklearn/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/__init__.py
Apache-2.0
def _autolog( # noqa: D417 flavor_name=FLAVOR_NAME, 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=Tru...
Internal autologging function for scikit-learn models. Args: flavor_name: A string value. Enable a ``mlflow.sklearn`` autologging routine for a flavor. By default it enables autologging for original scikit-learn models, as ``mlflow.sklearn.autolog()`` does. If the a...
_autolog
python
mlflow/mlflow
mlflow/sklearn/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/__init__.py
Apache-2.0
def fit_mlflow_xgboost_and_lightgbm(original, self, *args, **kwargs): """ Autologging function for XGBoost and LightGBM scikit-learn models """ # Obtain a copy of a model input example from the training dataset prior to model training # for subsequent use during model logging, en...
Autologging function for XGBoost and LightGBM scikit-learn models
fit_mlflow_xgboost_and_lightgbm
python
mlflow/mlflow
mlflow/sklearn/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/__init__.py
Apache-2.0
def fit_mlflow(original, self, *args, **kwargs): """ Autologging function that performs model training by executing the training method referred to be `func_name` on the instance of `clazz` referred to by `self` & records MLflow parameters, metrics, tags, and artifacts to a corresponding...
Autologging function that performs model training by executing the training method referred to be `func_name` on the instance of `clazz` referred to by `self` & records MLflow parameters, metrics, tags, and artifacts to a corresponding MLflow Run.
fit_mlflow
python
mlflow/mlflow
mlflow/sklearn/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/__init__.py
Apache-2.0
def _log_pretraining_metadata(autologging_client, estimator, X, y): # noqa: D417 """ Records metadata (e.g., params and tags) for a scikit-learn estimator prior to training. This is intended to be invoked within a patched scikit-learn training routine (e.g., `fit()`, `fit_transform()`, ...
Records metadata (e.g., params and tags) for a scikit-learn estimator prior to training. This is intended to be invoked within a patched scikit-learn training routine (e.g., `fit()`, `fit_transform()`, ...) and assumes the existence of an active MLflow run that can be referenced via the...
_log_pretraining_metadata
python
mlflow/mlflow
mlflow/sklearn/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/__init__.py
Apache-2.0
def _log_posttraining_metadata(autologging_client, estimator, X, y, sample_weight): """ Records metadata for a scikit-learn estimator after training has completed. This is intended to be invoked within a patched scikit-learn training routine (e.g., `fit()`, `fit_transform()`, ...) and as...
Records metadata for a scikit-learn estimator after training has completed. This is intended to be invoked within a patched scikit-learn training routine (e.g., `fit()`, `fit_transform()`, ...) and assumes the existence of an active MLflow run that can be referenced via the fluent Track...
_log_posttraining_metadata
python
mlflow/mlflow
mlflow/sklearn/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/__init__.py
Apache-2.0
def patched_fit(fit_impl, allow_children_patch, original, self, *args, **kwargs): """ Autologging patch function to be applied to a sklearn model class that defines a `fit` method and inherits from `BaseEstimator` (thereby defining the `get_params()` method) Args: fit_impl: ...
Autologging patch function to be applied to a sklearn model class that defines a `fit` method and inherits from `BaseEstimator` (thereby defining the `get_params()` method) Args: fit_impl: The patched fit function implementation, the function should be defined as `f...
patched_fit
python
mlflow/mlflow
mlflow/sklearn/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/__init__.py
Apache-2.0
def patched_predict(original, self, *args, **kwargs): """ In `patched_predict`, register the prediction result instance with the run id and eval dataset name. e.g. ``` prediction_result = model_1.predict(eval_X) ``` then we need register the following relationshi...
In `patched_predict`, register the prediction result instance with the run id and eval dataset name. e.g. ``` prediction_result = model_1.predict(eval_X) ``` then we need register the following relationship into the `_AUTOLOGGING_METRICS_MANAGER`: id(prediction_...
patched_predict
python
mlflow/mlflow
mlflow/sklearn/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/__init__.py
Apache-2.0
def patched_IffHasAttrDescriptor__get__(self, obj, type=None): """ For sklearn version <= 0.24.2, `_IffHasAttrDescriptor.__get__` method does not support unbound method call. See https://github.com/scikit-learn/scikit-learn/issues/20614 Thi...
For sklearn version <= 0.24.2, `_IffHasAttrDescriptor.__get__` method does not support unbound method call. See https://github.com/scikit-learn/scikit-learn/issues/20614 This patched function is for hot patch.
patched_IffHasAttrDescriptor__get__
python
mlflow/mlflow
mlflow/sklearn/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sklearn/__init__.py
Apache-2.0
def set_span_chat_attributes(span: LiveSpan, messages: list[dict[str, Any]], output: Any): """ This method logs chat messages to a span when LLM class is called. Args: span: A span object to record the chat messages. messages: Input messages for the LLM call. output: Response from L...
This method logs chat messages to a span when LLM class is called. Args: span: A span object to record the chat messages. messages: Input messages for the LLM call. output: Response from LLM. Though the signature is str, tool response might be returned.
set_span_chat_attributes
python
mlflow/mlflow
mlflow/smolagents/chat.py
https://github.com/mlflow/mlflow/blob/master/mlflow/smolagents/chat.py
Apache-2.0
def autolog( log_traces: bool = True, disable: bool = False, silent: bool = False, ): """ Enables (or disables) and configures autologging from Smolagents to MLflow. Note that asynchnorous APIs and Tool calling are not recorded now. Args: log_traces: If ``True``, traces are logged f...
Enables (or disables) and configures autologging from Smolagents to MLflow. Note that asynchnorous APIs and Tool calling are not recorded now. Args: log_traces: If ``True``, traces are logged for Smolagents agents. If ``False``, no traces are collected during inference. Default to ``Tr...
autolog
python
mlflow/mlflow
mlflow/smolagents/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/smolagents/__init__.py
Apache-2.0
def predict( self, dataframe, params: Optional[dict[str, Any]] = None, ): """Only works for predicting using text categorizer. Not suitable for other pipeline components (e.g: parser) Args: dataframe: pandas dataframe containing texts to be categorized ...
Only works for predicting using text categorizer. Not suitable for other pipeline components (e.g: parser) Args: dataframe: pandas dataframe containing texts to be categorized expected shape is (n_rows,1 column) params: Additional parameters to pass to the...
predict
python
mlflow/mlflow
mlflow/spacy/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/spacy/__init__.py
Apache-2.0
def load_model(model_uri, dst_path=None): """Load a spaCy model from a local file (if ``run_id`` is ``None``) 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/l...
Load a spaCy model from a local file (if ``run_id`` is ``None``) 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_bu...
load_model
python
mlflow/mlflow
mlflow/spacy/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/spacy/__init__.py
Apache-2.0
def clear_table_infos(): """Clear the table info accumulated SparkAutologgingContext. This is currently only used in unit tests. """ with _lock: global _table_infos _table_infos = []
Clear the table info accumulated SparkAutologgingContext. This is currently only used in unit tests.
clear_table_infos
python
mlflow/mlflow
mlflow/spark/autologging.py
https://github.com/mlflow/mlflow/blob/master/mlflow/spark/autologging.py
Apache-2.0
def _get_jvm_event_publisher(spark_context): """ Get JVM-side object implementing the following methods: - init() for initializing JVM state needed for autologging (e.g. attaching a SparkListener to watch for datasource reads) - register(subscriber) for registering subscribers to receive datasourc...
Get JVM-side object implementing the following methods: - init() for initializing JVM state needed for autologging (e.g. attaching a SparkListener to watch for datasource reads) - register(subscriber) for registering subscribers to receive datasource events
_get_jvm_event_publisher
python
mlflow/mlflow
mlflow/spark/autologging.py
https://github.com/mlflow/mlflow/blob/master/mlflow/spark/autologging.py
Apache-2.0
def _get_repl_id(): """ Get a unique REPL ID for a PythonSubscriber instance. This is used to distinguish between REPLs in multitenant, REPL-aware environments where multiple Python processes may share the same Spark JVM (e.g. in Databricks). In such environments, we pull the REPL ID from Spark loca...
Get a unique REPL ID for a PythonSubscriber instance. This is used to distinguish between REPLs in multitenant, REPL-aware environments where multiple Python processes may share the same Spark JVM (e.g. in Databricks). In such environments, we pull the REPL ID from Spark local properties, and expect th...
_get_repl_id
python
mlflow/mlflow
mlflow/spark/autologging.py
https://github.com/mlflow/mlflow/blob/master/mlflow/spark/autologging.py
Apache-2.0
def _notify(self, path, version, data_format): """ Method called by Scala SparkListener to propagate datasource read events to the current Python process """ if autologging_is_disabled(FLAVOR_NAME): return # If there are active runs, simply set the tag on the ...
Method called by Scala SparkListener to propagate datasource read events to the current Python process
_notify
python
mlflow/mlflow
mlflow/spark/autologging.py
https://github.com/mlflow/mlflow/blob/master/mlflow/spark/autologging.py
Apache-2.0
def 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 ...
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 v...
get_default_conda_env
python
mlflow/mlflow
mlflow/spark/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/spark/__init__.py
Apache-2.0
def log_model( spark_model, artifact_path, conda_env=None, code_paths=None, dfs_tmpdir=None, registered_model_name=None, signature: ModelSignature = None, input_example: ModelInputExample = None, await_registration_for=DEFAULT_AWAIT_MAX_SLEEP_SECONDS, pip_requirements=None, e...
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 s...
log_model
python
mlflow/mlflow
mlflow/spark/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/spark/__init__.py
Apache-2.0
def maybe_copy_from_local_file(cls, src, dst): """ Conditionally copy the file to the Hadoop DFS. The file is copied iff the configuration has distributed filesystem. Returns: If copied, return new target location, otherwise return (absolute) source path. """ ...
Conditionally copy the file to the Hadoop DFS. The file is copied iff the configuration has distributed filesystem. Returns: If copied, return new target location, otherwise return (absolute) source path.
maybe_copy_from_local_file
python
mlflow/mlflow
mlflow/spark/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/spark/__init__.py
Apache-2.0
def maybe_copy_from_uri(cls, src_uri, dst_path, local_model_path=None): """ Conditionally copy the file to the Hadoop DFS from the source uri. In case the file is already on the Hadoop DFS do nothing. Returns: If copied, return new target location, otherwise return source ur...
Conditionally copy the file to the Hadoop DFS from the source uri. In case the file is already on the Hadoop DFS do nothing. Returns: If copied, return new target location, otherwise return source uri.
maybe_copy_from_uri
python
mlflow/mlflow
mlflow/spark/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/spark/__init__.py
Apache-2.0
def _save_model_metadata( dst_dir, spark_model, mlflow_model, conda_env, code_paths, signature=None, input_example=None, pip_requirements=None, extra_pip_requirements=None, remote_model_path=None, ): """ Saves model metadata into the passed-in directory. If mlflowdbfs...
Saves model metadata into the passed-in directory. If mlflowdbfs is not used, the persisted metadata assumes that a model can be loaded from a relative path to the metadata file (currently hard-coded to "sparkml"). If mlflowdbfs is used, remote_model_path should be provided, and the model needs to ...
_save_model_metadata
python
mlflow/mlflow
mlflow/spark/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/spark/__init__.py
Apache-2.0
def _is_spark_connect_model(spark_model): """ Return whether the spark model is spark connect ML model """ try: from pyspark.ml.connect import Model as ConnectModel return isinstance(spark_model, ConnectModel) except ImportError: # pyspark < 3.5 does not support Spark connec...
Return whether the spark model is spark connect ML model
_is_spark_connect_model
python
mlflow/mlflow
mlflow/spark/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/spark/__init__.py
Apache-2.0
def save_model( spark_model, path, mlflow_model=None, conda_env=None, code_paths=None, dfs_tmpdir=None, signature: ModelSignature = None, input_example: ModelInputExample = None, pip_requirements=None, extra_pip_requirements=None, metadata=None, ): """ Save a Spark ML...
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 MLReada...
save_model
python
mlflow/mlflow
mlflow/spark/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/spark/__init__.py
Apache-2.0
def _load_pyfunc(path): """ Load PyFunc implementation. Called by ``pyfunc.load_model``. Args: path: Local filesystem path to the MLflow Model with the ``spark`` flavor. """ from mlflow.utils._spark_utils import ( _create_local_spark_session_for_loading_spark_model, _get_act...
Load PyFunc implementation. Called by ``pyfunc.load_model``. Args: path: Local filesystem path to the MLflow Model with the ``spark`` flavor.
_load_pyfunc
python
mlflow/mlflow
mlflow/spark/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/spark/__init__.py
Apache-2.0
def _find_and_set_features_col_as_vector_if_needed(spark_df, spark_model): """ Finds the `featuresCol` column in spark_model and then tries to cast that column to `vector` type. This method is noop if the `featuresCol` is already of type `vector` or if it can't be cast to `vector` type Note: ...
Finds the `featuresCol` column in spark_model and then tries to cast that column to `vector` type. This method is noop if the `featuresCol` is already of type `vector` or if it can't be cast to `vector` type Note: If a spark ML pipeline contains a single Estimator stage, it requires the inp...
_find_and_set_features_col_as_vector_if_needed
python
mlflow/mlflow
mlflow/spark/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/spark/__init__.py
Apache-2.0
def predict( self, pandas_df, params: Optional[dict[str, Any]] = None, ): """ Generate predictions given input data in a pandas DataFrame. Args: pandas_df: pandas DataFrame containing input data. params: Additional parameters to pass to the mo...
Generate predictions given input data in a pandas DataFrame. Args: pandas_df: pandas DataFrame containing input data. params: Additional parameters to pass to the model for inference. Returns: List with model predictions.
predict
python
mlflow/mlflow
mlflow/spark/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/spark/__init__.py
Apache-2.0
def save_model( statsmodels_model, path, conda_env=None, code_paths=None, mlflow_model=None, remove_data: bool = False, signature: ModelSignature = None, input_example: ModelInputExample = None, pip_requirements=None, extra_pip_requirements=None, metadata=None, ): """ ...
Save a statsmodels model to a path on the local file system. Args: statsmodels_model: statsmodels model (an instance of `statsmodels.base.model.Results`_) to be saved. path: Local path where the model is to be saved. conda_env: {{ conda_env }} code_paths: {{ code_pa...
save_model
python
mlflow/mlflow
mlflow/statsmodels/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/statsmodels/__init__.py
Apache-2.0
def log_model( statsmodels_model, artifact_path: Optional[str] = None, conda_env=None, code_paths=None, registered_model_name=None, remove_data: bool = False, signature: ModelSignature = None, input_example: ModelInputExample = None, await_registration_for=DEFAULT_AWAIT_MAX_SLEEP_SEC...
Log a statsmodels model as an MLflow artifact for the current run. Args: statsmodels_model: statsmodels model (an instance of `statsmodels.base.model.Results`_) to be saved. artifact_path: Deprecated. Use `name` instead. conda_env: {{ conda_env }} code_paths: {{ cod...
log_model
python
mlflow/mlflow
mlflow/statsmodels/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/statsmodels/__init__.py
Apache-2.0
def load_model(model_uri, dst_path=None): """ Load a statsmodels 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_...
Load a statsmodels 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:/<mlf...
load_model
python
mlflow/mlflow
mlflow/statsmodels/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/statsmodels/__init__.py
Apache-2.0
def find_subclasses(klass): """ Recursively return a (non-nested) list of the class object and all its subclasses. Args: klass: The class whose class subtree we want to retrieve. Returns: A list of classes that includes the argument in the first position. ...
Recursively return a (non-nested) list of the class object and all its subclasses. Args: klass: The class whose class subtree we want to retrieve. Returns: A list of classes that includes the argument in the first position.
find_subclasses
python
mlflow/mlflow
mlflow/statsmodels/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/statsmodels/__init__.py
Apache-2.0
def overrides(klass, function_name): """ Returns True when the class passed as first argument overrides the function_name Based on https://stackoverflow.com/a/62303206/5726057 Args: klass: The class we are inspecting. function_name: A string with the name of the ...
Returns True when the class passed as first argument overrides the function_name Based on https://stackoverflow.com/a/62303206/5726057 Args: klass: The class we are inspecting. function_name: A string with the name of the method we want to check overriding. Ret...
overrides
python
mlflow/mlflow
mlflow/statsmodels/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/statsmodels/__init__.py
Apache-2.0
def patch_class_tree(klass): """ Patches all subclasses that override any auto-loggable method via monkey patching using the gorilla package, taking the argument as the tree root in the class hierarchy. Every auto-loggable method found in any of the subclasses is replaced by the patched ...
Patches all subclasses that override any auto-loggable method via monkey patching using the gorilla package, taking the argument as the tree root in the class hierarchy. Every auto-loggable method found in any of the subclasses is replaced by the patched version. Args: klas...
patch_class_tree
python
mlflow/mlflow
mlflow/statsmodels/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/statsmodels/__init__.py
Apache-2.0
def _retry_with_new_creds(try_func, creds_func, orig_creds=None): """ Attempt the try_func with the original credentials (og_creds) if provided, or by generating the credentials using creds_func. If the try_func throws, then try again with new credentials provided by creds_func. """ try: ...
Attempt the try_func with the original credentials (og_creds) if provided, or by generating the credentials using creds_func. If the try_func throws, then try again with new credentials provided by creds_func.
_retry_with_new_creds
python
mlflow/mlflow
mlflow/store/artifact/artifact_repo.py
https://github.com/mlflow/mlflow/blob/master/mlflow/store/artifact/artifact_repo.py
Apache-2.0
def log_artifact(self, local_file, artifact_path=None): """ Log a local file as an artifact, optionally taking an ``artifact_path`` to place it in within the run's artifacts. Run artifacts can be organized into directories, so you can place the artifact in a directory this way. ...
Log a local file as an artifact, optionally taking an ``artifact_path`` to place it in within the run's artifacts. Run artifacts can be organized into directories, so you can place the artifact in a directory this way. Args: local_file: Path to artifact to log. ...
log_artifact
python
mlflow/mlflow
mlflow/store/artifact/artifact_repo.py
https://github.com/mlflow/mlflow/blob/master/mlflow/store/artifact/artifact_repo.py
Apache-2.0
def _log_artifact_async(self, filename, artifact_path=None, artifact=None): """ Asynchronously log a local file as an artifact, optionally taking an ``artifact_path`` to place it within the run's artifacts. Run artifacts can be organized into directory, so you can place the artifact in t...
Asynchronously log a local file as an artifact, optionally taking an ``artifact_path`` to place it within the run's artifacts. Run artifacts can be organized into directory, so you can place the artifact in the directory this way. Cleanup tells the function whether to cleanup the local_...
_log_artifact_async
python
mlflow/mlflow
mlflow/store/artifact/artifact_repo.py
https://github.com/mlflow/mlflow/blob/master/mlflow/store/artifact/artifact_repo.py
Apache-2.0
def log_artifacts(self, local_dir, artifact_path=None): """ Log the files in the specified local directory as artifacts, optionally taking an ``artifact_path`` to place them in within the run's artifacts. Args: local_dir: Directory of local artifacts to log. arti...
Log the files in the specified local directory as artifacts, optionally taking an ``artifact_path`` to place them in within the run's artifacts. Args: local_dir: Directory of local artifacts to log. artifact_path: Directory within the run's artifact directory in which t...
log_artifacts
python
mlflow/mlflow
mlflow/store/artifact/artifact_repo.py
https://github.com/mlflow/mlflow/blob/master/mlflow/store/artifact/artifact_repo.py
Apache-2.0
def list_artifacts(self, path: Optional[str] = None) -> list[FileInfo]: """ Return all the artifacts for this run_id directly under path. If path is a file, returns an empty list. Will error if path is neither a file nor directory. Args: path: Relative source path that conta...
Return all the artifacts for this run_id directly under path. If path is a file, returns an empty list. Will error if path is neither a file nor directory. Args: path: Relative source path that contains desired artifacts. Returns: List of artifacts as FileInfo ...
list_artifacts
python
mlflow/mlflow
mlflow/store/artifact/artifact_repo.py
https://github.com/mlflow/mlflow/blob/master/mlflow/store/artifact/artifact_repo.py
Apache-2.0
def _create_download_destination(self, src_artifact_path, dst_local_dir_path=None): """ Creates a local filesystem location to be used as a destination for downloading the artifact specified by `src_artifact_path`. The destination location is a subdirectory of the specified `dst_local_di...
Creates a local filesystem location to be used as a destination for downloading the artifact specified by `src_artifact_path`. The destination location is a subdirectory of the specified `dst_local_dir_path`, which is determined according to the structure of `src_artifact_path`. For exa...
_create_download_destination
python
mlflow/mlflow
mlflow/store/artifact/artifact_repo.py
https://github.com/mlflow/mlflow/blob/master/mlflow/store/artifact/artifact_repo.py
Apache-2.0
def download_artifacts(self, artifact_path, dst_path=None): """ Download an artifact file or directory to a local directory if applicable, and return a local path for it. The caller is responsible for managing the lifecycle of the downloaded artifacts. Args: artifact...
Download an artifact file or directory to a local directory if applicable, and return a local path for it. The caller is responsible for managing the lifecycle of the downloaded artifacts. Args: artifact_path: Relative source path to the desired artifacts. dst_p...
download_artifacts
python
mlflow/mlflow
mlflow/store/artifact/artifact_repo.py
https://github.com/mlflow/mlflow/blob/master/mlflow/store/artifact/artifact_repo.py
Apache-2.0