def test_model_log_persists_requirements_in_mlflow_model_directory( sklearn_knn_model, main_scoped_model_class, pyfunc_custom_env): sklearn_artifact_path = "sk_model" with mlflow.start_run(): mlflow.sklearn.log_model(sk_model=sklearn_knn_model, artifact_path=sklearn_artifact_path) sklearn_run_id = mlflow.active_run().info.run_id pyfunc_artifact_path = "pyfunc_model" with mlflow.start_run(): mlflow.pyfunc.log_model( artifact_path=pyfunc_artifact_path, artifacts={ "sk_model": utils_get_artifact_uri(artifact_path=sklearn_artifact_path, run_id=sklearn_run_id) }, python_model=main_scoped_model_class(predict_fn=None), conda_env=pyfunc_custom_env, ) pyfunc_model_path = _download_artifact_from_uri( "runs:/{run_id}/{artifact_path}".format( run_id=mlflow.active_run().info.run_id, artifact_path=pyfunc_artifact_path)) saved_pip_req_path = os.path.join(pyfunc_model_path, "requirements.txt") _compare_conda_env_requirements(pyfunc_custom_env, saved_pip_req_path)
def test_model_save_persists_requirements_in_mlflow_model_directory( model, model_path, keras_custom_env ): mlflow.keras.save_model(keras_model=model, path=model_path, conda_env=keras_custom_env) saved_pip_req_path = os.path.join(model_path, "requirements.txt") _compare_conda_env_requirements(keras_custom_env, saved_pip_req_path)
def test_model_save_persists_requirements_in_mlflow_model_directory( h2o_iris_model, model_path, h2o_custom_env ): mlflow.h2o.save_model(h2o_model=h2o_iris_model.model, path=model_path, conda_env=h2o_custom_env) saved_pip_req_path = os.path.join(model_path, "requirements.txt") _compare_conda_env_requirements(h2o_custom_env, saved_pip_req_path)
def test_model_save_persists_requirements_in_mlflow_model_directory( xgb_model, model_path, xgb_custom_env ): mlflow.xgboost.save_model(xgb_model=xgb_model.model, path=model_path, conda_env=xgb_custom_env) saved_pip_req_path = os.path.join(model_path, "requirements.txt") _compare_conda_env_requirements(xgb_custom_env, saved_pip_req_path)
def test_model_save_persists_requirements_in_mlflow_model_directory( onnx_model, model_path, onnx_custom_env): mlflow.onnx.save_model(onnx_model=onnx_model, path=model_path, conda_env=onnx_custom_env) saved_pip_req_path = os.path.join(model_path, "requirements.txt") _compare_conda_env_requirements(onnx_custom_env, saved_pip_req_path)
def test_model_save_persists_requirements_in_mlflow_model_directory( sklearn_knn_model, model_path, sklearn_custom_env): mlflow.sklearn.save_model(sk_model=sklearn_knn_model.model, path=model_path, conda_env=sklearn_custom_env) saved_pip_req_path = os.path.join(model_path, "requirements.txt") _compare_conda_env_requirements(sklearn_custom_env, saved_pip_req_path)
def test_model_save_persists_requirements_in_mlflow_model_directory( spacy_model_with_data, model_path, spacy_custom_env): mlflow.spacy.save_model(spacy_model=spacy_model_with_data.model, path=model_path, conda_env=spacy_custom_env) saved_pip_req_path = os.path.join(model_path, "requirements.txt") _compare_conda_env_requirements(spacy_custom_env, saved_pip_req_path)
def test_model_save_persists_requirements_in_mlflow_model_directory( fastai_model, model_path, fastai_custom_env): mlflow.fastai.save_model(fastai_learner=fastai_model.model, path=model_path, conda_env=fastai_custom_env) saved_pip_req_path = os.path.join(model_path, "requirements.txt") _compare_conda_env_requirements(fastai_custom_env, saved_pip_req_path)
def test_diviner_model_save_persists_requirements_in_mlflow_model_directory( grouped_pmdarima, model_path, diviner_custom_env ): mlflow.diviner.save_model( diviner_model=grouped_pmdarima, path=model_path, conda_env=str(diviner_custom_env) ) saved_pip_req_path = model_path.joinpath("requirements.txt") _compare_conda_env_requirements(diviner_custom_env, str(saved_pip_req_path))
def test_sparkml_model_save_persists_requirements_in_mlflow_model_directory( spark_model_iris, model_path, spark_custom_env): sparkm.save_model(spark_model=spark_model_iris.model, path=model_path, conda_env=spark_custom_env) saved_pip_req_path = os.path.join(model_path, "requirements.txt") _compare_conda_env_requirements(spark_custom_env, saved_pip_req_path)
def test_model_save_persists_requirements_in_mlflow_model_directory( sequential_model, model_path, pytorch_custom_env): mlflow.pytorch.save_model(pytorch_model=sequential_model, path=model_path, conda_env=pytorch_custom_env) saved_pip_req_path = os.path.join(model_path, "requirements.txt") _compare_conda_env_requirements(pytorch_custom_env, saved_pip_req_path)
def test_model_save_persists_requirements_in_mlflow_model_directory( prophet_model, model_path, prophet_custom_env): mlflow.prophet.save_model(pr_model=prophet_model.model, path=model_path, conda_env=prophet_custom_env) saved_pip_req_path = os.path.join(model_path, "requirements.txt") _compare_conda_env_requirements(prophet_custom_env, saved_pip_req_path)
def test_pmdarima_model_save_persists_requirements_in_mlflow_model_directory( auto_arima_model, model_path, pmdarima_custom_env): mlflow.pmdarima.save_model(pmdarima_model=auto_arima_model, path=model_path, conda_env=pmdarima_custom_env) saved_pip_req_path = os.path.join(model_path, "requirements.txt") _compare_conda_env_requirements(pmdarima_custom_env, saved_pip_req_path)
def test_model_log_persists_requirements_in_mlflow_model_directory(reg_model, custom_env): artifact_path = "model" with mlflow.start_run(): mlflow.catboost.log_model(reg_model.model, artifact_path, conda_env=custom_env) model_uri = mlflow.get_artifact_uri(artifact_path) local_path = _download_artifact_from_uri(artifact_uri=model_uri) saved_pip_req_path = os.path.join(local_path, "requirements.txt") _compare_conda_env_requirements(custom_env, saved_pip_req_path)
def test_model_save_persists_requirements_in_mlflow_model_directory( model_path, statsmodels_custom_env): ols = ols_model() mlflow.statsmodels.save_model(statsmodels_model=ols.model, path=model_path, conda_env=statsmodels_custom_env) saved_pip_req_path = os.path.join(model_path, "requirements.txt") _compare_conda_env_requirements(statsmodels_custom_env, saved_pip_req_path)
def test_save_model_persists_requirements_in_mlflow_model_directory( saved_tf_iris_model, model_path, tf_custom_env): mlflow.tensorflow.save_model( tf_saved_model_dir=saved_tf_iris_model.path, tf_meta_graph_tags=saved_tf_iris_model.meta_graph_tags, tf_signature_def_key=saved_tf_iris_model.signature_def_key, path=model_path, conda_env=tf_custom_env, ) saved_pip_req_path = os.path.join(model_path, "requirements.txt") _compare_conda_env_requirements(tf_custom_env, saved_pip_req_path)
def test_model_log_persists_requirements_in_mlflow_model_directory(xgb_model, xgb_custom_env): artifact_path = "model" with mlflow.start_run(): mlflow.xgboost.log_model( xgb_model=xgb_model.model, artifact_path=artifact_path, conda_env=xgb_custom_env ) model_uri = "runs:/{run_id}/{artifact_path}".format( run_id=mlflow.active_run().info.run_id, artifact_path=artifact_path ) model_path = _download_artifact_from_uri(artifact_uri=model_uri) saved_pip_req_path = os.path.join(model_path, "requirements.txt") _compare_conda_env_requirements(xgb_custom_env, saved_pip_req_path)
def test_model_log_persists_requirements_in_mlflow_model_directory( sequential_model, pytorch_custom_env): artifact_path = "model" with mlflow.start_run(): mlflow.pytorch.log_model( pytorch_model=sequential_model, artifact_path=artifact_path, conda_env=pytorch_custom_env, ) model_path = _download_artifact_from_uri( "runs:/{run_id}/{artifact_path}".format( run_id=mlflow.active_run().info.run_id, artifact_path=artifact_path)) saved_pip_req_path = os.path.join(model_path, "requirements.txt") _compare_conda_env_requirements(pytorch_custom_env, saved_pip_req_path)
def test_log_model_persists_requirements_in_mlflow_model_directory( saved_tf_iris_model, tf_custom_env): artifact_path = "model" with mlflow.start_run(): mlflow.tensorflow.log_model( tf_saved_model_dir=saved_tf_iris_model.path, tf_meta_graph_tags=saved_tf_iris_model.meta_graph_tags, tf_signature_def_key=saved_tf_iris_model.signature_def_key, artifact_path=artifact_path, conda_env=tf_custom_env, ) model_uri = "runs:/{run_id}/{artifact_path}".format( run_id=mlflow.active_run().info.run_id, artifact_path=artifact_path) model_path = _download_artifact_from_uri(artifact_uri=model_uri) saved_pip_req_path = os.path.join(model_path, "requirements.txt") _compare_conda_env_requirements(tf_custom_env, saved_pip_req_path)
def test_save_model_persists_requirements_in_mlflow_model_directory( sklearn_knn_model, main_scoped_model_class, pyfunc_custom_env, tmpdir): sklearn_model_path = os.path.join(str(tmpdir), "sklearn_model") mlflow.sklearn.save_model( sk_model=sklearn_knn_model, path=sklearn_model_path, serialization_format=mlflow.sklearn.SERIALIZATION_FORMAT_CLOUDPICKLE, ) pyfunc_model_path = os.path.join(str(tmpdir), "pyfunc_model") mlflow.pyfunc.save_model( path=pyfunc_model_path, artifacts={"sk_model": sklearn_model_path}, python_model=main_scoped_model_class(predict_fn=None), conda_env=pyfunc_custom_env, ) saved_pip_req_path = os.path.join(pyfunc_model_path, "requirements.txt") _compare_conda_env_requirements(pyfunc_custom_env, saved_pip_req_path)