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 _simulate_serving_environment(): """ Some functions (e.g. validate_serving_input) replicate the data transformation logic that happens in the model serving environment to validate data before model deployment. This context manager can be used to simulate the serving environment for such functions. ...
Some functions (e.g. validate_serving_input) replicate the data transformation logic that happens in the model serving environment to validate data before model deployment. This context manager can be used to simulate the serving environment for such functions.
_simulate_serving_environment
python
mlflow/mlflow
mlflow/pyfunc/utils/environment.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pyfunc/utils/environment.py
Apache-2.0
def _is_optional_dataclass(field_type) -> bool: """ Check if the field type is an Optional containing a dataclass. Currently, ... | None (in Python 3.10) is not supported. """ if get_origin(field_type) is Union: inner_types = get_args(field_type) # Check if it's a Union[Dataclass, No...
Check if the field type is an Optional containing a dataclass. Currently, ... | None (in Python 3.10) is not supported.
_is_optional_dataclass
python
mlflow/mlflow
mlflow/pyfunc/utils/input_converter.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pyfunc/utils/input_converter.py
Apache-2.0
def _hydrate_dataclass(dataclass_type, data): """Recursively create an instance of the dataclass_type from data.""" if not (is_dataclass(dataclass_type) or _is_optional_dataclass(dataclass_type)): raise ValueError(f"{dataclass_type.__name__} is not a dataclass") if data is None: return None ...
Recursively create an instance of the dataclass_type from data.
_hydrate_dataclass
python
mlflow/mlflow
mlflow/pyfunc/utils/input_converter.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pyfunc/utils/input_converter.py
Apache-2.0
def cast_spark_df_with_vector_to_array(input_spark_df): # noqa: D417 """ Finds columns of vector type in a spark dataframe and casts them to array<double> type. Args: input_spark_df: Returns: A spark dataframe with vector columns transformed to array<double> type """ vecto...
Finds columns of vector type in a spark dataframe and casts them to array<double> type. Args: input_spark_df: Returns: A spark dataframe with vector columns transformed to array<double> type
cast_spark_df_with_vector_to_array
python
mlflow/mlflow
mlflow/pyspark/ml/_autolog.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pyspark/ml/_autolog.py
Apache-2.0
def _get_struct_type_by_cols(input_fields: set[str], df_schema: t.StructType) -> t.StructType: """ Args: input_fields: A set of input columns to be intersected with the input dataset's columns. df_schema: A Spark dataframe schema to compare input_fields Returns: ...
Args: input_fields: A set of input columns to be intersected with the input dataset's columns. df_schema: A Spark dataframe schema to compare input_fields Returns: A StructType from the intersection of given columns and the columns present in the training da...
_get_struct_type_by_cols
python
mlflow/mlflow
mlflow/pyspark/ml/_autolog.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pyspark/ml/_autolog.py
Apache-2.0
def get_feature_cols( df: DataFrame, transformer: Union[Transformer, PipelineModel], ) -> set[str]: """ Finds feature columns from an input dataset. If a dataset contains non-feature columns, those columns are not returned, but if `input_fields` is set to include non-feature columns those wi...
Finds feature columns from an input dataset. If a dataset contains non-feature columns, those columns are not returned, but if `input_fields` is set to include non-feature columns those will be included in the return set of column names. Args: df: An input spark dataframe. transfor...
get_feature_cols
python
mlflow/mlflow
mlflow/pyspark/ml/_autolog.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pyspark/ml/_autolog.py
Apache-2.0
def _read_log_model_allowlist(): """ Reads the module allowlist and returns it as a set. """ from mlflow.utils._spark_utils import _get_active_spark_session # New in 3.9: https://docs.python.org/3/library/importlib.resources.html#importlib.resources.files if sys.version_info.major > 2 and sys.v...
Reads the module allowlist and returns it as a set.
_read_log_model_allowlist
python
mlflow/mlflow
mlflow/pyspark/ml/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pyspark/ml/__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": _get_fully_qualified_class_name(estimator), }
Returns: A dictionary of MLflow run tag keys and values describing the specified estimator.
_get_estimator_info_tags
python
mlflow/mlflow
mlflow/pyspark/ml/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pyspark/ml/__init__.py
Apache-2.0
def _gen_estimator_metadata(estimator): """ Returns an `_AutologgingEstimatorMetadata` object. The `_AutologgingEstimatorMetadata` object includes: - hierarchy: the hierarchy of the estimator, it will expand pipeline/meta estimator/param tuning estimator - uid_to_indexed_name_map: a map o...
Returns an `_AutologgingEstimatorMetadata` object. The `_AutologgingEstimatorMetadata` object includes: - hierarchy: the hierarchy of the estimator, it will expand pipeline/meta estimator/param tuning estimator - uid_to_indexed_name_map: a map of `uid` -> `name`, each nested instance uid wil...
_gen_estimator_metadata
python
mlflow/mlflow
mlflow/pyspark/ml/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pyspark/ml/__init__.py
Apache-2.0
def _get_stage_type_params(instance): """ Get the param map of the instance where param value is of type pyspark.ml.param.Params """ from pyspark.ml.param import Params return { param.name: instance.getOrDefault(param) for param in instance.params if instance.isDefined(param...
Get the param map of the instance where param value is of type pyspark.ml.param.Params
_get_stage_type_params
python
mlflow/mlflow
mlflow/pyspark/ml/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pyspark/ml/__init__.py
Apache-2.0
def _get_param_search_metrics_and_best_index(param_search_estimator, param_search_model): """ Return a tuple of `(metrics_dict, best_index)` `metrics_dict` is a dict of metric_name --> metric_values for each param map - For CrossValidatorModel, the result dict contains metrics of avg_metris and std_metr...
Return a tuple of `(metrics_dict, best_index)` `metrics_dict` is a dict of metric_name --> metric_values for each param map - For CrossValidatorModel, the result dict contains metrics of avg_metris and std_metrics for each param map. - For TrainValidationSplitModel, the result dict contains metri...
_get_param_search_metrics_and_best_index
python
mlflow/mlflow
mlflow/pyspark/ml/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pyspark/ml/__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/pyspark/ml/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pyspark/ml/__init__.py
Apache-2.0
def register_prediction_input_dataset(self, model, eval_dataset): """ Register prediction input dataset into eval_dataset_info_map, it will do: 1. inspect eval dataset var name. 2. check whether eval_dataset_info_map already registered this eval dataset. will check by objec...
Register prediction input dataset into eval_dataset_info_map, it will do: 1. inspect eval dataset var name. 2. check whether eval_dataset_info_map already registered this eval dataset. will check by object id. 3. register eval dataset with id. 4. return eval data...
register_prediction_input_dataset
python
mlflow/mlflow
mlflow/pyspark/ml/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pyspark/ml/__init__.py
Apache-2.0
def register_prediction_result(self, run_id, eval_dataset_name, predict_result): """ Register the relationship id(prediction_result) --> (eval_dataset_name, run_id) into map `_pred_result_id_to_dataset_name_and_run_id` """ value = (eval_dataset_name, run_id) pred...
Register the relationship id(prediction_result) --> (eval_dataset_name, run_id) into map `_pred_result_id_to_dataset_name_and_run_id`
register_prediction_result
python
mlflow/mlflow
mlflow/pyspark/ml/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pyspark/ml/__init__.py
Apache-2.0
def get_run_id_and_dataset_name_for_evaluator_call(self, pred_result_dataset): """ Given a registered prediction result dataset object, return a tuple of (run_id, eval_dataset_name) """ if id(pred_result_dataset) in self._pred_result_id_to_dataset_name_and_run_id: dat...
Given a registered prediction result dataset object, return a tuple of (run_id, eval_dataset_name)
get_run_id_and_dataset_name_for_evaluator_call
python
mlflow/mlflow
mlflow/pyspark/ml/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pyspark/ml/__init__.py
Apache-2.0
def gen_evaluator_info(self, evaluator): """ Generate evaluator information, include evaluator class name and params. """ class_name = _get_fully_qualified_class_name(evaluator) param_map = _truncate_dict( _get_param_map(evaluator), MAX_ENTITY_KEY_LENGTH, MAX_PARAM_VA...
Generate evaluator information, include evaluator class name and params.
gen_evaluator_info
python
mlflow/mlflow
mlflow/pyspark/ml/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pyspark/ml/__init__.py
Apache-2.0
def register_evaluator_call(self, run_id, metric_name, dataset_name, evaluator_info): """ Register the `Evaluator.evaluate` call, including register the evaluator information (See doc of `gen_evaluator_info` method) into the corresponding run_id and metric_name entry in the registry tabl...
Register the `Evaluator.evaluate` call, including register the evaluator information (See doc of `gen_evaluator_info` method) into the corresponding run_id and metric_name entry in the registry table.
register_evaluator_call
python
mlflow/mlflow
mlflow/pyspark/ml/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pyspark/ml/__init__.py
Apache-2.0
def log_post_training_metric(self, run_id, key, value): """ Log the metric into the specified mlflow run. and it will also update the metric_info artifact if needed. """ # Note: if the case log the same metric key multiple times, # newer value will overwrite old value ...
Log the metric into the specified mlflow run. and it will also update the metric_info artifact if needed.
log_post_training_metric
python
mlflow/mlflow
mlflow/pyspark/ml/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pyspark/ml/__init__.py
Apache-2.0
def is_spark_connect_mode() -> bool: """Check if the current Spark session is running in client mode.""" try: from pyspark.sql.utils import is_remote except ImportError: return False return is_remote()
Check if the current Spark session is running in client mode.
is_spark_connect_mode
python
mlflow/mlflow
mlflow/pyspark/optuna/study.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pyspark/optuna/study.py
Apache-2.0
def _optimize_sequential( study: "optuna.Study", func: "optuna.study.study.ObjectiveFuncType", mlflow_client: MlflowClient, n_trials: int = 1, timeout: Optional[float] = None, catch: Iterable[type[Exception]] = (), callbacks: Optional[Iterable[Callable[[Study, FrozenTrial], None]]] = None, )...
Run optimization sequentially. It is modified from _optimize_sequential in optuna (https://github.com/optuna/optuna/blob/e1e30e7150047e5f582b8fef1eeb65386cb1c4c1/optuna/study/_optimize.py#L121) Convert the nested call to one function and log the error messages to mlflow.
_optimize_sequential
python
mlflow/mlflow
mlflow/pyspark/optuna/study.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pyspark/optuna/study.py
Apache-2.0
def _get_optimizer_name(optimizer): """ In pytorch-lightning 1.1.0, `LightningOptimizer` was introduced: https://github.com/PyTorchLightning/pytorch-lightning/pull/4658 If a user sets `enable_pl_optimizer` to True when instantiating a `Trainer` object, each optimizer will be wrapped by `LightningOp...
In pytorch-lightning 1.1.0, `LightningOptimizer` was introduced: https://github.com/PyTorchLightning/pytorch-lightning/pull/4658 If a user sets `enable_pl_optimizer` to True when instantiating a `Trainer` object, each optimizer will be wrapped by `LightningOptimizer`: https://pytorch-lightning.rea...
_get_optimizer_name
python
mlflow/mlflow
mlflow/pytorch/_lightning_autolog.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pytorch/_lightning_autolog.py
Apache-2.0
def on_train_epoch_end(self, trainer, pl_module, *args): """ Log loss and other metrics values after each train epoch Args: trainer: pytorch lightning trainer instance pl_module: pytorch lightning base module args: additional positiona...
Log loss and other metrics values after each train epoch Args: trainer: pytorch lightning trainer instance pl_module: pytorch lightning base module args: additional positional arguments
on_train_epoch_end
python
mlflow/mlflow
mlflow/pytorch/_lightning_autolog.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pytorch/_lightning_autolog.py
Apache-2.0
def on_train_batch_end(self, trainer, pl_module, *args): """ Log metric values after each step Args: trainer: pytorch lightning trainer instance pl_module: pytorch lightning base module args: additional positional arguments """ if not self.log...
Log metric values after each step Args: trainer: pytorch lightning trainer instance pl_module: pytorch lightning base module args: additional positional arguments
on_train_batch_end
python
mlflow/mlflow
mlflow/pytorch/_lightning_autolog.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pytorch/_lightning_autolog.py
Apache-2.0
def on_train_start(self, trainer, pl_module): """ Logs Optimizer related metrics when the train begins Args: trainer: pytorch lightning trainer instance pl_module: pytorch lightning base module """ self.client.set_tags(self.run_id, {"Mode": "training"}) ...
Logs Optimizer related metrics when the train begins Args: trainer: pytorch lightning trainer instance pl_module: pytorch lightning base module
on_train_start
python
mlflow/mlflow
mlflow/pytorch/_lightning_autolog.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pytorch/_lightning_autolog.py
Apache-2.0
def on_test_end(self, trainer, pl_module): """ Logs accuracy and other relevant metrics on the testing end Args: trainer: pytorch lightning trainer instance pl_module: pytorch lightning base module """ self.client.set_tags(self.run_id, {"Mode": "testing"}...
Logs accuracy and other relevant metrics on the testing end Args: trainer: pytorch lightning trainer instance pl_module: pytorch lightning base module
on_test_end
python
mlflow/mlflow
mlflow/pytorch/_lightning_autolog.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pytorch/_lightning_autolog.py
Apache-2.0
def _log_early_stop_metrics(early_stop_callback, client, run_id, model_id=None): """ Logs early stopping behavior results (e.g. stopped epoch) as metrics to MLflow. Args: early_stop_callback: The early stopping callback instance used during training. client: An `MlflowAutologgingQueueingCli...
Logs early stopping behavior results (e.g. stopped epoch) as metrics to MLflow. Args: early_stop_callback: The early stopping callback instance used during training. client: An `MlflowAutologgingQueueingClient` instance used for MLflow logging. run_id: The ID of the MLflow Run to which...
_log_early_stop_metrics
python
mlflow/mlflow
mlflow/pytorch/_lightning_autolog.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pytorch/_lightning_autolog.py
Apache-2.0
def patched_fit(original, self, *args, **kwargs): """ A patched implementation of `pytorch_lightning.Trainer.fit` which enables logging the following parameters, metrics and artifacts: - Training epochs - Optimizer parameters - `EarlyStoppingCallback`_ parameters - Metrics stored in `traine...
A patched implementation of `pytorch_lightning.Trainer.fit` which enables logging the following parameters, metrics and artifacts: - Training epochs - Optimizer parameters - `EarlyStoppingCallback`_ parameters - Metrics stored in `trainer.callback_metrics` - Model checkpoints - Trained...
patched_fit
python
mlflow/mlflow
mlflow/pytorch/_lightning_autolog.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pytorch/_lightning_autolog.py
Apache-2.0
def patched_add_hparams(original, self, hparam_dict, metric_dict, *args, **kwargs): """use a synchronous call here since this is going to get called very infrequently.""" run = mlflow.active_run() if run is not None and hparam_dict: run_id = run.info.run_id # str() is required by mlflow :(...
use a synchronous call here since this is going to get called very infrequently.
patched_add_hparams
python
mlflow/mlflow
mlflow/pytorch/_pytorch_autolog.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pytorch/_pytorch_autolog.py
Apache-2.0
def get_default_pip_requirements(): """ Returns: A list of default pip requirements for MLflow Models produced by this flavor. Calls to :func:`save_model()` and :func:`log_model()` produce a pip environment that, at minimum, contains these requirements. """ return list( m...
Returns: A list of default pip requirements for MLflow Models produced by this flavor. Calls to :func:`save_model()` and :func:`log_model()` produce a pip environment that, at minimum, contains these requirements.
get_default_pip_requirements
python
mlflow/mlflow
mlflow/pytorch/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pytorch/__init__.py
Apache-2.0
def log_model( pytorch_model, artifact_path: Optional[str] = None, conda_env=None, code_paths=None, pickle_module=None, registered_model_name=None, signature: ModelSignature = None, input_example: ModelInputExample = None, await_registration_for=DEFAULT_AWAIT_MAX_SLEEP_SECONDS, e...
Log a PyTorch model as an MLflow artifact for the current run. .. warning:: Log the model with a signature to avoid inference errors. If the model is logged without a signature, the MLflow Model Server relies on the default inferred data type from NumPy. However, PyTorch often expects differen...
log_model
python
mlflow/mlflow
mlflow/pytorch/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pytorch/__init__.py
Apache-2.0
def save_model( pytorch_model, path, conda_env=None, mlflow_model=None, code_paths=None, pickle_module=None, signature: ModelSignature = None, input_example: ModelInputExample = None, extra_files=None, pip_requirements=None, extra_pip_requirements=None, metadata=None, ...
Save a PyTorch model to a path on the local file system. Args: pytorch_model: PyTorch model to be saved. Can be either an eager model (subclass of ``torch.nn.Module``) or a scripted model prepared via ``torch.jit.script`` or ``torch.jit.trace``. To save an eager mo...
save_model
python
mlflow/mlflow
mlflow/pytorch/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pytorch/__init__.py
Apache-2.0
def _load_model(path, device=None, **kwargs): """ Args: path: The path to a serialized PyTorch model. device: If specified, load the model on the specified device. kwargs: Additional kwargs to pass to the PyTorch ``torch.load`` function. """ import torch if os.path.isdir(pat...
Args: path: The path to a serialized PyTorch model. device: If specified, load the model on the specified device. kwargs: Additional kwargs to pass to the PyTorch ``torch.load`` function.
_load_model
python
mlflow/mlflow
mlflow/pytorch/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pytorch/__init__.py
Apache-2.0
def load_model(model_uri, dst_path=None, **kwargs): """ Load a PyTorch model from a local file or a run. Args: model_uri: The location, in URI format, of the MLflow model, for example: - ``/Users/me/path/to/local/model`` - ``relative/path/to/local/model`` - ``s3...
Load a PyTorch model from a local file or a run. Args: model_uri: The location, in URI format, of the MLflow model, for example: - ``/Users/me/path/to/local/model`` - ``relative/path/to/local/model`` - ``s3://my_bucket/path/to/model`` - ``runs:/<mlflow_...
load_model
python
mlflow/mlflow
mlflow/pytorch/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pytorch/__init__.py
Apache-2.0
def _load_pyfunc(path, model_config=None, weights_only=False): # noqa: D417 """ Load PyFunc implementation. Called by ``pyfunc.load_model``. Args: path: Local filesystem path to the MLflow Model with the ``pytorch`` flavor. """ import torch device = model_config.get("device", None) if...
Load PyFunc implementation. Called by ``pyfunc.load_model``. Args: path: Local filesystem path to the MLflow Model with the ``pytorch`` flavor.
_load_pyfunc
python
mlflow/mlflow
mlflow/pytorch/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pytorch/__init__.py
Apache-2.0
def log_state_dict(state_dict, artifact_path, **kwargs): """ Log a state_dict as an MLflow artifact for the current run. .. warning:: This function just logs a state_dict as an artifact and doesn't generate an :ref:`MLflow Model <models>`. Args: state_dict: state_dict to be sav...
Log a state_dict as an MLflow artifact for the current run. .. warning:: This function just logs a state_dict as an artifact and doesn't generate an :ref:`MLflow Model <models>`. Args: state_dict: state_dict to be saved. artifact_path: Run-relative artifact path. k...
log_state_dict
python
mlflow/mlflow
mlflow/pytorch/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pytorch/__init__.py
Apache-2.0
def save_state_dict(state_dict, path, **kwargs): """ Save a state_dict to a path on the local file system Args: state_dict: state_dict to be saved. path: Local path where the state_dict is to be saved. kwargs: kwargs to pass to ``torch.save``. """ import torch # The obj...
Save a state_dict to a path on the local file system Args: state_dict: state_dict to be saved. path: Local path where the state_dict is to be saved. kwargs: kwargs to pass to ``torch.save``.
save_state_dict
python
mlflow/mlflow
mlflow/pytorch/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pytorch/__init__.py
Apache-2.0
def load_state_dict(state_dict_uri, **kwargs): """ Load a state_dict from a local file or a run. Args: state_dict_uri: The location, in URI format, of the state_dict, for example: - ``/Users/me/path/to/local/state_dict`` - ``relative/path/to/local/state_dict`` -...
Load a state_dict from a local file or a run. Args: state_dict_uri: The location, in URI format, of the state_dict, for example: - ``/Users/me/path/to/local/state_dict`` - ``relative/path/to/local/state_dict`` - ``s3://my_bucket/path/to/state_dict`` - `...
load_state_dict
python
mlflow/mlflow
mlflow/pytorch/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pytorch/__init__.py
Apache-2.0
def load_checkpoint(model_class, run_id=None, epoch=None, global_step=None, kwargs=None): """ If you enable "checkpoint" in autologging, during pytorch-lightning model training execution, checkpointed models are logged as MLflow artifacts. Using this API, you can load the checkpointed model. If you...
If you enable "checkpoint" in autologging, during pytorch-lightning model training execution, checkpointed models are logged as MLflow artifacts. Using this API, you can load the checkpointed model. If you want to load the latest checkpoint, set both `epoch` and `global_step` to None. If "checkpoi...
load_checkpoint
python
mlflow/mlflow
mlflow/pytorch/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/pytorch/__init__.py
Apache-2.0
def predict( self, model_uri, input_path, output_path, content_type, pip_requirements_override=None, extra_envs=None, ): """ Generate predictions using R model saved with MLflow. Return the prediction results as a JSON. """ ...
Generate predictions using R model saved with MLflow. Return the prediction results as a JSON.
predict
python
mlflow/mlflow
mlflow/rfunc/backend.py
https://github.com/mlflow/mlflow/blob/master/mlflow/rfunc/backend.py
Apache-2.0
def serve( self, model_uri, port, host, timeout, enable_mlserver, synchronous=True, stdout=None, stderr=None, ): """ Generate R model locally. NOTE: The `enable_mlserver` parameter is there to comply with the Fl...
Generate R model locally. NOTE: The `enable_mlserver` parameter is there to comply with the FlavorBackend interface but is not supported by MLServer yet. https://github.com/SeldonIO/MLServer/issues/183
serve
python
mlflow/mlflow
mlflow/rfunc/backend.py
https://github.com/mlflow/mlflow/blob/master/mlflow/rfunc/backend.py
Apache-2.0
def commands(): """ Serve models on SageMaker. To serve a model associated with a run on a tracking server, set the MLFLOW_TRACKING_URI environment variable to the URL of the desired server. """
Serve models on SageMaker. To serve a model associated with a run on a tracking server, set the MLFLOW_TRACKING_URI environment variable to the URL of the desired server.
commands
python
mlflow/mlflow
mlflow/sagemaker/cli.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/cli.py
Apache-2.0
def deploy_transform_job( job_name, model_uri, input_data_type, input_uri, content_type, output_path, compression_type, split_type, accept, assemble_with, input_filter, output_filter, join_resource, execution_role_arn, bucket, image_url, region_name, ...
Deploy model on Sagemaker as a batch transform job. Current active AWS account needs to have correct permissions setup. By default, unless the ``--async`` flag is specified, this command will block until either the batch transform job completes (definitively succeeds or fails) or the specified tim...
deploy_transform_job
python
mlflow/mlflow
mlflow/sagemaker/cli.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/cli.py
Apache-2.0
def terminate_transform_job(job_name, region_name, archive, asynchronous, timeout): """ Terminate the specified Sagemaker batch transform job. Unless ``--archive`` is specified, all SageMaker resources associated with the batch transform job are deleted as well. By default, unless the ``--async`` flag ...
Terminate the specified Sagemaker batch transform job. Unless ``--archive`` is specified, all SageMaker resources associated with the batch transform job are deleted as well. By default, unless the ``--async`` flag is specified, this command will block until either the termination process completes (d...
terminate_transform_job
python
mlflow/mlflow
mlflow/sagemaker/cli.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/cli.py
Apache-2.0
def push_model_to_sagemaker( model_name, model_uri, execution_role_arn, bucket, image_url, region_name, vpc_config, flavor, ): """ Push an MLflow model to Sagemaker model registry. Current active AWS account needs to have correct permissions setup. """ if vpc_config i...
Push an MLflow model to Sagemaker model registry. Current active AWS account needs to have correct permissions setup.
push_model_to_sagemaker
python
mlflow/mlflow
mlflow/sagemaker/cli.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/cli.py
Apache-2.0
def build_and_push_container(build, push, container, install_java, env_manager, mlflow_home): """ Build new MLflow Sagemaker image, assign it a name, and push to ECR. This function builds an MLflow Docker image. The image is built locally and it requires Docker to run. The image is pushed to ECR un...
Build new MLflow Sagemaker image, assign it a name, and push to ECR. This function builds an MLflow Docker image. The image is built locally and it requires Docker to run. The image is pushed to ECR under current active AWS account and to current active AWS region.
build_and_push_container
python
mlflow/mlflow
mlflow/sagemaker/cli.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/cli.py
Apache-2.0
def _get_preferred_deployment_flavor(model_config): """ Obtains the flavor that MLflow would prefer to use when deploying the model. If the model does not contain any supported flavors for deployment, an exception will be thrown. Args: model_config: An MLflow model object Returns: ...
Obtains the flavor that MLflow would prefer to use when deploying the model. If the model does not contain any supported flavors for deployment, an exception will be thrown. Args: model_config: An MLflow model object Returns: The name of the preferred deployment flavor for the spe...
_get_preferred_deployment_flavor
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def _validate_deployment_flavor(model_config, flavor): """ Checks that the specified flavor is a supported deployment flavor and is contained in the specified model. If one of these conditions is not met, an exception is thrown. Args: model_config: An MLflow Model object flavor: The...
Checks that the specified flavor is a supported deployment flavor and is contained in the specified model. If one of these conditions is not met, an exception is thrown. Args: model_config: An MLflow Model object flavor: The deployment flavor to validate
_validate_deployment_flavor
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def push_image_to_ecr(image=DEFAULT_IMAGE_NAME): """ Push local Docker image to AWS ECR. The image is pushed under currently active AWS account and to the currently active AWS region. Args: image: Docker image name. """ import boto3 _logger.info("Pushing image to ECR") client ...
Push local Docker image to AWS ECR. The image is pushed under currently active AWS account and to the currently active AWS region. Args: image: Docker image name.
push_image_to_ecr
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def _deploy( app_name, model_uri, execution_role_arn=None, assume_role_arn=None, bucket=None, image_url=None, region_name="us-west-2", mode=DEPLOYMENT_MODE_CREATE, archive=False, instance_type=DEFAULT_SAGEMAKER_INSTANCE_TYPE, instance_count=DEFAULT_SAGEMAKER_INSTANCE_COUNT, ...
Deploy an MLflow model on AWS SageMaker. The currently active AWS account must have correct permissions set up. This function creates a SageMaker endpoint. For more information about the input data formats accepted by this endpoint, see the `MLflow deployment tools documentation <../../deployment/...
_deploy
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def _delete( app_name, region_name="us-west-2", assume_role_arn=None, archive=False, synchronous=True, timeout_seconds=300, ): """ Delete a SageMaker application. Args: app_name: Name of the deployed application. region_name: Name of the AWS region in which the appli...
Delete a SageMaker application. Args: app_name: Name of the deployed application. region_name: Name of the AWS region in which the application is deployed. assume_role_arn: The name of an IAM cross-account role to be assumed to deploy SageMaker to another AWS account. If un...
_delete
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def deploy_transform_job( job_name, model_uri, s3_input_data_type, s3_input_uri, content_type, s3_output_path, compression_type="None", split_type="Line", accept="text/csv", assemble_with="Line", input_filter="$", output_filter="$", join_resource="None", execution...
Deploy an MLflow model on AWS SageMaker and create the corresponding batch transform job. The currently active AWS account must have correct permissions set up. Args: job_name: Name of the deployed Sagemaker batch transform job. model_uri: The location, in URI format, of the MLflow model t...
deploy_transform_job
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def terminate_transform_job( job_name, region_name="us-west-2", assume_role_arn=None, archive=False, synchronous=True, timeout_seconds=300, ): """ Terminate a SageMaker batch transform job. Args: job_name: Name of the deployed Sagemaker batch transform job. region_na...
Terminate a SageMaker batch transform job. Args: job_name: Name of the deployed Sagemaker batch transform job. region_name: Name of the AWS region in which the batch transform job is deployed. assume_role_arn: The name of an IAM cross-account role to be assumed to deploy SageMaker ...
terminate_transform_job
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def push_model_to_sagemaker( model_name, model_uri, execution_role_arn=None, assume_role_arn=None, bucket=None, image_url=None, region_name="us-west-2", vpc_config=None, flavor=None, ): """ Create a SageMaker Model from an MLflow model artifact. The currently active AWS a...
Create a SageMaker Model from an MLflow model artifact. The currently active AWS account must have correct permissions set up. Args: model_name: Name of the Sagemaker model. model_uri: The location, in URI format, of the MLflow model to deploy to SageMaker. For example: ...
push_model_to_sagemaker
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def run_local(name, model_uri, flavor=None, config=None): """ Serve the model locally in a SageMaker compatible Docker container. Note that models deployed locally cannot be managed by other deployment APIs (e.g. ``update_deployment``, ``delete_deployment``, etc). Args: name: Name of the l...
Serve the model locally in a SageMaker compatible Docker container. Note that models deployed locally cannot be managed by other deployment APIs (e.g. ``update_deployment``, ``delete_deployment``, etc). Args: name: Name of the local serving application. model_uri: The location, in URI...
run_local
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def target_help(): """ Provide help information for the SageMaker deployment client. """ return """\ For detailed documentation on the SageMaker deployment client, please visit https://mlflow.org/docs/latest/python_api/mlflow.sagemaker.html#mlflow.sagemaker.SageMakerDeploymentClient The tar...
Provide help information for the SageMaker deployment client.
target_help
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def _get_assumed_role_arn(**assume_role_credentials): """ Returns: ARN of the user's current IAM role. """ import boto3 sess = boto3.Session() sts_client = sess.client("sts", **assume_role_credentials) identity_info = sts_client.get_caller_identity() sts_arn = identity_info["Arn...
Returns: ARN of the user's current IAM role.
_get_assumed_role_arn
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def _assume_role_and_get_credentials(assume_role_arn=None): """ Assume a new role in AWS and return the credentials for that role. When ``assume_role_arn`` is ``None`` or an empty string, this function does nothing and returns an empty dictionary. Args: assume_role_arn: Optional ARN of the ...
Assume a new role in AWS and return the credentials for that role. When ``assume_role_arn`` is ``None`` or an empty string, this function does nothing and returns an empty dictionary. Args: assume_role_arn: Optional ARN of the role that will be assumed Returns: Dict with credentia...
_assume_role_and_get_credentials
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def _upload_s3(local_model_path, bucket, prefix, region_name, s3_client, **assume_role_credentials): # noqa: D417 """ Upload dir to S3 as .tar.gz. Args: local_model_path: Local path to a dir. bucket: S3 bucket where to store the data. prefix: Path within the bucket. region_...
Upload dir to S3 as .tar.gz. Args: local_model_path: Local path to a dir. bucket: S3 bucket where to store the data. prefix: Path within the bucket. region_name: The AWS region in which to upload data to S3. s3_client: A boto3 client for S3. Returns: S3 pat...
_upload_s3
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def _get_deployment_config(flavor_name, env_override=None): """ Returns: The deployment configuration as a dictionary """ deployment_config = { MLFLOW_DEPLOYMENT_FLAVOR_NAME.name: flavor_name, SERVING_ENVIRONMENT: SAGEMAKER_SERVING_ENVIRONMENT, } if env_override: ...
Returns: The deployment configuration as a dictionary
_get_deployment_config
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def _create_sagemaker_transform_job( job_name, model_name, model_s3_path, model_uri, image_url, flavor, vpc_config, role, sage_client, s3_client, instance_type, instance_count, s3_input_data_type, s3_input_uri, content_type, compression_type, split_typ...
Args: job_name: Name of the deployed Sagemaker batch transform job. model_name: The name to assign the new SageMaker model that will be associated with the specified batch transform job. model_s3_path: S3 path where we stored the model artifacts. model_uri: URI of the ML...
_create_sagemaker_transform_job
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def _create_sagemaker_endpoint( # noqa: D417 endpoint_name, model_name, model_s3_path, model_uri, image_url, flavor, instance_type, vpc_config, data_capture_config, instance_count, role, sage_client, variant_name=None, async_inference_config=None, serverless_...
Args: endpoint_name: The name of the SageMaker endpoint to create. model_name: The name to assign the new SageMaker model that will be associated with the specified endpoint. model_s3_path: S3 path where we stored the model artifacts. model_uri: URI of the MLflow model t...
_create_sagemaker_endpoint
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def _update_sagemaker_endpoint( # noqa: D417 endpoint_name, model_name, model_uri, image_url, model_s3_path, flavor, instance_type, instance_count, vpc_config, mode, role, sage_client, s3_client, variant_name=None, async_inference_config=None, serverless_...
Args: endpoint_name: The name of the SageMaker endpoint to update. model_name: The name to assign the new SageMaker model that will be associated with the specified endpoint. model_uri: URI of the MLflow model to associate with the specified SageMaker endpoint. image_url...
_update_sagemaker_endpoint
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def _create_sagemaker_model( model_name, model_s3_path, model_uri, flavor, vpc_config, image_url, execution_role, sage_client, env, tags, ): """ Args: model_name: The name to assign the new SageMaker model that is created. model_s3_path: S3 path where the ...
Args: model_name: The name to assign the new SageMaker model that is created. model_s3_path: S3 path where the model artifacts are stored. model_uri: URI of the MLflow model associated with the new SageMaker model. flavor: The name of the flavor of the model. vpc_config: A d...
_create_sagemaker_model
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def _delete_sagemaker_model(model_name, sage_client, s3_client): # noqa: D417 """ Args: sage_client: A boto3 client for SageMaker. s3_client: A boto3 client for S3. Returns: ARN of the deleted model. """ model_info = sage_client.describe_model(ModelName=model_name) mode...
Args: sage_client: A boto3 client for SageMaker. s3_client: A boto3 client for S3. Returns: ARN of the deleted model.
_delete_sagemaker_model
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def _delete_sagemaker_endpoint_configuration(endpoint_config_name, sage_client): # noqa: D417 """ Args: sage_client: A boto3 client for SageMaker. Returns: ARN of the deleted endpoint configuration. """ endpoint_config_info = sage_client.describe_endpoint_config( EndpointCo...
Args: sage_client: A boto3 client for SageMaker. Returns: ARN of the deleted endpoint configuration.
_delete_sagemaker_endpoint_configuration
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def _find_endpoint(endpoint_name, sage_client): # noqa: D417 """ Finds a SageMaker endpoint with the specified name in the caller's AWS account, returning a NoneType if the endpoint is not found. Args: sage_client: A boto3 client for SageMaker. Returns: If the endpoint exists, a d...
Finds a SageMaker endpoint with the specified name in the caller's AWS account, returning a NoneType if the endpoint is not found. Args: sage_client: A boto3 client for SageMaker. Returns: If the endpoint exists, a dictionary of endpoint attributes. If the endpoint does not ex...
_find_endpoint
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def _find_transform_job(job_name, sage_client): # noqa: D417 """ Finds a SageMaker batch transform job with the specified name in the caller's AWS account, returning a NoneType if the transform job is not found. Args: sage_client: A boto3 client for SageMaker. Returns: If the tran...
Finds a SageMaker batch transform job with the specified name in the caller's AWS account, returning a NoneType if the transform job is not found. Args: sage_client: A boto3 client for SageMaker. Returns: If the transform job exists, a dictionary of transform job attributes. If the ...
_find_transform_job
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def _does_model_exist(model_name, sage_client): # noqa: D417 """ Determines whether a SageMaker model exists with the specified name in the caller's AWS account, returning True if the model exists, returning False if the model does not exist. Args: sage_client: A boto3 client for SageMaker. ...
Determines whether a SageMaker model exists with the specified name in the caller's AWS account, returning True if the model exists, returning False if the model does not exist. Args: sage_client: A boto3 client for SageMaker. Returns: If the model exists, ``True``. If the model does ...
_does_model_exist
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def create_deployment(self, name, model_uri, flavor=None, config=None, endpoint=None): """ Deploy an MLflow model on AWS SageMaker. The currently active AWS account must have correct permissions set up. This function creates a SageMaker endpoint. For more information about the input dat...
Deploy an MLflow model on AWS SageMaker. The currently active AWS account must have correct permissions set up. This function creates a SageMaker endpoint. For more information about the input data formats accepted by this endpoint, see the `MLflow deployment tools documentatio...
create_deployment
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def update_deployment(self, name, model_uri, flavor=None, config=None, endpoint=None): """ Update a deployment on AWS SageMaker. This function can replace or add a new model to an existing SageMaker endpoint. By default, this function replaces the existing model with the new one. The cur...
Update a deployment on AWS SageMaker. This function can replace or add a new model to an existing SageMaker endpoint. By default, this function replaces the existing model with the new one. The currently active AWS account must have correct permissions set up. Args: name: N...
update_deployment
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def delete_deployment(self, name, config=None, endpoint=None): """ Delete a SageMaker application. Args: name: Name of the deployed application. config: Configuration parameters. The supported parameters are: - ``assume_role_arn``: The name of an IAM rol...
Delete a SageMaker application. Args: name: Name of the deployed application. config: Configuration parameters. The supported parameters are: - ``assume_role_arn``: The name of an IAM role to be assumed to delete the SageMaker deployment. ...
delete_deployment
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def list_deployments(self, endpoint=None): """ List deployments. This method returns a list of dictionaries that describes each deployment. If a region name needs to be specified, the plugin must be initialized with the AWS region in the ``target_uri`` such as ``sagemaker:/us-east-1``. ...
List deployments. This method returns a list of dictionaries that describes each deployment. If a region name needs to be specified, the plugin must be initialized with the AWS region in the ``target_uri`` such as ``sagemaker:/us-east-1``. To assume an IAM role, the plugin must be ini...
list_deployments
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def get_deployment(self, name, endpoint=None): """ Returns a dictionary describing the specified deployment. If a region name needs to be specified, the plugin must be initialized with the AWS region in the ``target_uri`` such as ``sagemaker:/us-east-1``. To assume an IAM role,...
Returns a dictionary describing the specified deployment. If a region name needs to be specified, the plugin must be initialized with the AWS region in the ``target_uri`` such as ``sagemaker:/us-east-1``. To assume an IAM role, the plugin must be initialized with the AWS regio...
get_deployment
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def predict( self, deployment_name=None, inputs=None, endpoint=None, params: Optional[dict[str, Any]] = None, ): """ Compute predictions from the specified deployment using the provided PyFunc input. The input/output types of this method match the :re...
Compute predictions from the specified deployment using the provided PyFunc input. The input/output types of this method match the :ref:`MLflow PyFunc prediction interface <pyfunc-inference-api>`. If a region name needs to be specified, the plugin must be initialized with the ...
predict
python
mlflow/mlflow
mlflow/sagemaker/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sagemaker/__init__.py
Apache-2.0
def get_default_pip_requirements() -> list[str]: """ Retrieves the set of minimal dependencies for the ``sentence_transformers`` flavor. Returns: A list of default pip requirements for MLflow Models that have been produced with the ``sentence-transformers`` flavor. Calls to :py:func:`save_m...
Retrieves the set of minimal dependencies for the ``sentence_transformers`` flavor. Returns: A list of default pip requirements for MLflow Models that have been produced with the ``sentence-transformers`` flavor. Calls to :py:func:`save_model()` and :py:func:`log_model()` produce a pip...
get_default_pip_requirements
python
mlflow/mlflow
mlflow/sentence_transformers/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sentence_transformers/__init__.py
Apache-2.0
def save_model( model, path: str, task: Optional[str] = None, inference_config: Optional[dict[str, Any]] = None, code_paths: Optional[list[str]] = None, mlflow_model: Optional[Model] = None, signature: Optional[ModelSignature] = None, input_example: Optional[ModelInputExample] = None, ...
.. note:: Saving Sentence Transformers models with custom code (i.e. models that require ``trust_remote_code=True``) is supported in MLflow 2.12.0 and above. Save a trained ``sentence-transformers`` model to a path on the local file system. Args: model: A trained ``sentence-tran...
save_model
python
mlflow/mlflow
mlflow/sentence_transformers/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sentence_transformers/__init__.py
Apache-2.0
def _get_transformers_model_metadata(model) -> dict[str, str]: """ Extract metadata about the underlying Transformers model, such as the model class name and the repository id. Args: model: A SentenceTransformer model instance. Returns: A dictionary containing metadata about the Tr...
Extract metadata about the underlying Transformers model, such as the model class name and the repository id. Args: model: A SentenceTransformer model instance. Returns: A dictionary containing metadata about the Transformers model.
_get_transformers_model_metadata
python
mlflow/mlflow
mlflow/sentence_transformers/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sentence_transformers/__init__.py
Apache-2.0
def log_model( model, artifact_path: Optional[str] = None, task: Optional[str] = None, inference_config: Optional[dict[str, Any]] = None, code_paths: Optional[list[str]] = None, registered_model_name: Optional[str] = None, signature: Optional[ModelSignature] = None, input_example: Option...
.. note:: Logging Sentence Transformers models with custom code (i.e. models that require ``trust_remote_code=True``) is supported in MLflow 2.12.0 and above. Log a ``sentence_transformers`` model as an MLflow artifact for the current run. .. code-block:: python # An example of ...
log_model
python
mlflow/mlflow
mlflow/sentence_transformers/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sentence_transformers/__init__.py
Apache-2.0
def _load_pyfunc(path, model_config: Optional[dict[str, Any]] = None): # noqa: D417 """ Load PyFunc implementation for SentenceTransformer. Called by ``pyfunc.load_model``. Args: path: Local filesystem path to the MLflow Model with the ``sentence_transformer`` flavor. """ import sentence_t...
Load PyFunc implementation for SentenceTransformer. Called by ``pyfunc.load_model``. Args: path: Local filesystem path to the MLflow Model with the ``sentence_transformer`` flavor.
_load_pyfunc
python
mlflow/mlflow
mlflow/sentence_transformers/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sentence_transformers/__init__.py
Apache-2.0
def load_model(model_uri: str, dst_path: Optional[str] = None): """ Load a ``sentence_transformers`` object from a local file or a run. Args: model_uri: The location, in URI format, of the MLflow model. For example: - ``/Users/me/path/to/local/model`` - ``relative/path/to/l...
Load a ``sentence_transformers`` object from a local file or a run. Args: model_uri: The location, in URI format, of the MLflow model. For example: - ``/Users/me/path/to/local/model`` - ``relative/path/to/local/model`` - ``s3://my_bucket/path/to/model`` ...
load_model
python
mlflow/mlflow
mlflow/sentence_transformers/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sentence_transformers/__init__.py
Apache-2.0
def _get_default_signature(): """ Generates a default signature for the ``sentence_transformers`` flavor to be applied if not set or overridden by supplying the `signature` argument to `log_model` or `save_model`. """ return ModelSignature( inputs=Schema([ColSpec("string")]), outputs...
Generates a default signature for the ``sentence_transformers`` flavor to be applied if not set or overridden by supplying the `signature` argument to `log_model` or `save_model`.
_get_default_signature
python
mlflow/mlflow
mlflow/sentence_transformers/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sentence_transformers/__init__.py
Apache-2.0
def predict(self, sentences, params: Optional[dict[str, Any]] = None): """ Args: sentences: Model input data. params: Additional parameters to pass to the model for inference. Returns: Model predictions. """ # When the input is a single string...
Args: sentences: Model input data. params: Additional parameters to pass to the model for inference. Returns: Model predictions.
predict
python
mlflow/mlflow
mlflow/sentence_transformers/__init__.py
https://github.com/mlflow/mlflow/blob/master/mlflow/sentence_transformers/__init__.py
Apache-2.0
def _get_artifact_repo_mlflow_artifacts(): """ Get an artifact repository specified by ``--artifacts-destination`` option for ``mlflow server`` command. """ from mlflow.server import ARTIFACTS_DESTINATION_ENV_VAR global _artifact_repo if _artifact_repo is None: _artifact_repo = get_...
Get an artifact repository specified by ``--artifacts-destination`` option for ``mlflow server`` command.
_get_artifact_repo_mlflow_artifacts
python
mlflow/mlflow
mlflow/server/handlers.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/handlers.py
Apache-2.0
def _get_trace_artifact_repo(trace_info: TraceInfoV2): """ Resolve the artifact repository for fetching data for the given trace. Args: trace_info: The trace info object containing metadata about the trace. """ artifact_uri = get_artifact_uri_for_trace(trace_info) if _is_servable_proxi...
Resolve the artifact repository for fetching data for the given trace. Args: trace_info: The trace info object containing metadata about the trace.
_get_trace_artifact_repo
python
mlflow/mlflow
mlflow/server/handlers.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/handlers.py
Apache-2.0
def _is_serving_proxied_artifacts(): """ Returns: True if the MLflow server is serving proxied artifacts (i.e. acting as a proxy for artifact upload / download / list operations), as would be enabled by specifying the --serve-artifacts configuration option. False otherwise. """ f...
Returns: True if the MLflow server is serving proxied artifacts (i.e. acting as a proxy for artifact upload / download / list operations), as would be enabled by specifying the --serve-artifacts configuration option. False otherwise.
_is_serving_proxied_artifacts
python
mlflow/mlflow
mlflow/server/handlers.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/handlers.py
Apache-2.0
def _is_servable_proxied_run_artifact_root(run_artifact_root): """ Determines whether or not the following are true: - The specified Run artifact root is a proxied artifact root (i.e. an artifact root with scheme ``http``, ``https``, or ``mlflow-artifacts``). - The MLflow server is capable of re...
Determines whether or not the following are true: - The specified Run artifact root is a proxied artifact root (i.e. an artifact root with scheme ``http``, ``https``, or ``mlflow-artifacts``). - The MLflow server is capable of resolving and accessing the underlying storage location correspond...
_is_servable_proxied_run_artifact_root
python
mlflow/mlflow
mlflow/server/handlers.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/handlers.py
Apache-2.0
def _get_proxied_run_artifact_destination_path(proxied_artifact_root, relative_path=None): """ Resolves the specified proxied artifact location within a Run to a concrete storage location. Args: proxied_artifact_root: The Run artifact root location (URI) with scheme ``http``, ``https``,...
Resolves the specified proxied artifact location within a Run to a concrete storage location. Args: proxied_artifact_root: The Run artifact root location (URI) with scheme ``http``, ``https``, or `mlflow-artifacts` that can be resolved by the MLflow server to a concrete storage...
_get_proxied_run_artifact_destination_path
python
mlflow/mlflow
mlflow/server/handlers.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/handlers.py
Apache-2.0
def _validate_param_against_schema(schema, param, value, proto_parsing_succeeded=False): """ Attempts to validate a single parameter against a specified schema. Examples of the elements of the schema are type assertions and checks for required parameters. Returns None on validation success. Otherwise, ...
Attempts to validate a single parameter against a specified schema. Examples of the elements of the schema are type assertions and checks for required parameters. Returns None on validation success. Otherwise, raises an MLFlowException if an assertion fails. This method is intended to be called for si...
_validate_param_against_schema
python
mlflow/mlflow
mlflow/server/handlers.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/handlers.py
Apache-2.0
def _list_artifacts_for_proxied_run_artifact_root(proxied_artifact_root, relative_path=None): """ Lists artifacts from the specified ``relative_path`` within the specified proxied Run artifact root (i.e. a Run artifact root with scheme ``http``, ``https``, or ``mlflow-artifacts``). Args: proxie...
Lists artifacts from the specified ``relative_path`` within the specified proxied Run artifact root (i.e. a Run artifact root with scheme ``http``, ``https``, or ``mlflow-artifacts``). Args: proxied_artifact_root: The Run artifact root location (URI) with scheme ``http``, ...
_list_artifacts_for_proxied_run_artifact_root
python
mlflow/mlflow
mlflow/server/handlers.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/handlers.py
Apache-2.0
def _validate_non_local_source_contains_relative_paths(source: str): """ Validation check to ensure that sources that are provided that conform to the schemes: http, https, or mlflow-artifacts do not contain relative path designations that are intended to access local file system paths on the tracking s...
Validation check to ensure that sources that are provided that conform to the schemes: http, https, or mlflow-artifacts do not contain relative path designations that are intended to access local file system paths on the tracking server. Example paths that this validation function is intended to find ...
_validate_non_local_source_contains_relative_paths
python
mlflow/mlflow
mlflow/server/handlers.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/handlers.py
Apache-2.0
def _download_artifact(artifact_path): """ A request handler for `GET /mlflow-artifacts/artifacts/<artifact_path>` to download an artifact from `artifact_path` (a relative path from the root artifact directory). """ artifact_path = validate_path_is_safe(artifact_path) tmp_dir = tempfile.Temporar...
A request handler for `GET /mlflow-artifacts/artifacts/<artifact_path>` to download an artifact from `artifact_path` (a relative path from the root artifact directory).
_download_artifact
python
mlflow/mlflow
mlflow/server/handlers.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/handlers.py
Apache-2.0
def _upload_artifact(artifact_path): """ A request handler for `PUT /mlflow-artifacts/artifacts/<artifact_path>` to upload an artifact to `artifact_path` (a relative path from the root artifact directory). """ artifact_path = validate_path_is_safe(artifact_path) head, tail = posixpath.split(arti...
A request handler for `PUT /mlflow-artifacts/artifacts/<artifact_path>` to upload an artifact to `artifact_path` (a relative path from the root artifact directory).
_upload_artifact
python
mlflow/mlflow
mlflow/server/handlers.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/handlers.py
Apache-2.0
def _list_artifacts_mlflow_artifacts(): """ A request handler for `GET /mlflow-artifacts/artifacts?path=<value>` to list artifacts in `path` (a relative path from the root artifact directory). """ request_message = _get_request_message(ListArtifactsMlflowArtifacts()) path = validate_path_is_safe...
A request handler for `GET /mlflow-artifacts/artifacts?path=<value>` to list artifacts in `path` (a relative path from the root artifact directory).
_list_artifacts_mlflow_artifacts
python
mlflow/mlflow
mlflow/server/handlers.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/handlers.py
Apache-2.0
def _delete_artifact_mlflow_artifacts(artifact_path): """ A request handler for `DELETE /mlflow-artifacts/artifacts?path=<value>` to delete artifacts in `path` (a relative path from the root artifact directory). """ artifact_path = validate_path_is_safe(artifact_path) _get_request_message(Delete...
A request handler for `DELETE /mlflow-artifacts/artifacts?path=<value>` to delete artifacts in `path` (a relative path from the root artifact directory).
_delete_artifact_mlflow_artifacts
python
mlflow/mlflow
mlflow/server/handlers.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/handlers.py
Apache-2.0
def _create_multipart_upload_artifact(artifact_path): """ A request handler for `POST /mlflow-artifacts/mpu/create` to create a multipart upload to `artifact_path` (a relative path from the root artifact directory). """ artifact_path = validate_path_is_safe(artifact_path) request_message = _get...
A request handler for `POST /mlflow-artifacts/mpu/create` to create a multipart upload to `artifact_path` (a relative path from the root artifact directory).
_create_multipart_upload_artifact
python
mlflow/mlflow
mlflow/server/handlers.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/handlers.py
Apache-2.0
def _complete_multipart_upload_artifact(artifact_path): """ A request handler for `POST /mlflow-artifacts/mpu/complete` to complete a multipart upload to `artifact_path` (a relative path from the root artifact directory). """ artifact_path = validate_path_is_safe(artifact_path) request_message ...
A request handler for `POST /mlflow-artifacts/mpu/complete` to complete a multipart upload to `artifact_path` (a relative path from the root artifact directory).
_complete_multipart_upload_artifact
python
mlflow/mlflow
mlflow/server/handlers.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/handlers.py
Apache-2.0
def _abort_multipart_upload_artifact(artifact_path): """ A request handler for `POST /mlflow-artifacts/mpu/abort` to abort a multipart upload to `artifact_path` (a relative path from the root artifact directory). """ artifact_path = validate_path_is_safe(artifact_path) request_message = _get_re...
A request handler for `POST /mlflow-artifacts/mpu/abort` to abort a multipart upload to `artifact_path` (a relative path from the root artifact directory).
_abort_multipart_upload_artifact
python
mlflow/mlflow
mlflow/server/handlers.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/handlers.py
Apache-2.0
def _start_trace(): """ A request handler for `POST /mlflow/traces` to create a new TraceInfo record in tracking store. """ request_message = _get_request_message( StartTrace(), schema={ "experiment_id": [_assert_string], "timestamp_ms": [_assert_intlike], ...
A request handler for `POST /mlflow/traces` to create a new TraceInfo record in tracking store.
_start_trace
python
mlflow/mlflow
mlflow/server/handlers.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/handlers.py
Apache-2.0
def _end_trace(request_id): """ A request handler for `PATCH /mlflow/traces/{request_id}` to mark an existing TraceInfo record completed in tracking store. """ request_message = _get_request_message( EndTrace(), schema={ "timestamp_ms": [_assert_intlike], "sta...
A request handler for `PATCH /mlflow/traces/{request_id}` to mark an existing TraceInfo record completed in tracking store.
_end_trace
python
mlflow/mlflow
mlflow/server/handlers.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/handlers.py
Apache-2.0
def _get_trace_info(request_id): """ A request handler for `GET /mlflow/traces/{request_id}/info` to retrieve an existing TraceInfo record from tracking store. """ trace_info = _get_tracking_store().get_trace_info(request_id) response_message = GetTraceInfo.Response(trace_info=trace_info.to_prot...
A request handler for `GET /mlflow/traces/{request_id}/info` to retrieve an existing TraceInfo record from tracking store.
_get_trace_info
python
mlflow/mlflow
mlflow/server/handlers.py
https://github.com/mlflow/mlflow/blob/master/mlflow/server/handlers.py
Apache-2.0